Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ali-middleware-5-sync
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
ali-middleware-5-sync
Commits
f487bb44
There was an error fetching the commit references. Please try again later.
Commit
f487bb44
authored
5 years ago
by
郭浩
Browse files
Options
Downloads
Patches
Plain Diff
Update consumer
parent
52eb3c6c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java
+14
-23
14 additions, 23 deletions
...onsumer/src/main/java/com/aliware/tianchi/MyConsumer.java
pom.xml
+5
-1
5 additions, 1 deletion
pom.xml
with
19 additions
and
24 deletions
internal-service/service-consumer/src/main/java/com/aliware/tianchi/MyConsumer.java
+
14
−
23
View file @
f487bb44
package
com.aliware.tianchi
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.List
;
import
org.apache.dubbo.common.Constants
;
import
org.apache.dubbo.common.URL
;
import
org.apache.dubbo.config.ApplicationConfig
;
import
org.apache.dubbo.config.ReferenceConfig
;
import
org.apache.dubbo.config.RegistryConfig
;
/** @author guohaoice@gmail.com */
/**
* Gateway 启动入口
* @author guohaoice@gmail.com */
public
class
MyConsumer
{
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
{
// 当前应用配置
public
static
void
main
(
String
[]
args
)
throws
InterruptedException
{
ApplicationConfig
application
=
new
ApplicationConfig
();
application
.
setName
(
"service-gateway"
);
//
连接
注册中心
配置
//
直连方式,不使用
注册中心
RegistryConfig
registry
=
new
RegistryConfig
();
// String address="com.aliware.tianchi.HashInterface-"
// +"localhost:20880_"
// +"localhost:20880";
// registry.setAddress("list://localhost:9999");
registry
.
setAddress
(
"N/A"
);
// registry.setParameters(Collections.singletonMap(LIST_URL_KEY,address));
// 注意:ReferenceConfig为重对象,内部封装了与注册中心的连接,以及与服务提供方的连接
// 引用远程服务
ReferenceConfig
<
HashInterface
>
reference
=
new
ReferenceConfig
<
HashInterface
>();
// 此实例很重,封装了与注册中心的连接以及与提供者的连接,请自行缓存,否则可能造成内存和连接泄漏
ReferenceConfig
<
HashInterface
>
reference
=
new
ReferenceConfig
<>();
reference
.
setApplication
(
application
);
reference
.
setRegistry
(
registry
);
// 多个注册中心可以用setRegistries()
reference
.
setRegistry
(
registry
);
reference
.
setInterface
(
HashInterface
.
class
);
// reference.setUrl(new URL(Constants.DUBBO_PROTOCOL,"localhost",20880,reference.getInterface()));
reference
.
setUrl
(
"localhost:20880"
);
// 和本地bean一样使用xxxService
HashInterface
service
=
reference
.
get
();
// 注意:此代理对象内部封装了所有通讯细节,对象较重,请缓存复用
List
<
URL
>
urls
=
reference
.
toUrls
();
// 添加直连的 provider 地址
urls
.
add
(
new
URL
(
Constants
.
DUBBO_PROTOCOL
,
"localhost"
,
20880
,
reference
.
getInterface
()));
urls
.
add
(
new
URL
(
Constants
.
DUBBO_PROTOCOL
,
"localhost"
,
20880
,
reference
.
getInterface
()));
HashInterface
service
=
reference
.
get
();
while
(
true
)
{
Thread
.
sleep
(
1000
);
System
.
out
.
println
(
service
.
hash
(
"hahaha"
));
...
...
This diff is collapsed.
Click to expand it.
pom.xml
+
5
−
1
View file @
f487bb44
...
...
@@ -59,7 +59,6 @@
<version>
${project.version}
</version>
</dependency>
<!--internal end-->
<dependency>
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
...
...
@@ -70,6 +69,11 @@
<artifactId>
logback-classic
</artifactId>
<version>
1.2.3
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<version>
3.9
</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment