Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
0c3334dd
Commit
0c3334dd
authored
Mar 07, 2022
by
hweeeeeei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完成Dubbo指定ip调用
parent
0a5d9918
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
33 deletions
+137
-33
bootstrap/src/test/java/io/geekidea/springbootplus/test/DubboRpcTest.java
+56
-0
config/src/main/resources/config/bootstrap.yml
+46
-0
core/src/main/java/com/wecloud/im/ws/sender/ChannelSender.java
+9
-2
pom.xml
+26
-31
No files found.
bootstrap/src/test/java/io/geekidea/springbootplus/test/DubboRpcTest.java
0 → 100644
View file @
0c3334dd
package
io
.
geekidea
.
springbootplus
.
test
;
import
com.wecloud.im.router.RouterSendService
;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.utils.JsonUtils
;
import
org.apache.dubbo.config.annotation.DubboReference
;
import
org.apache.dubbo.rpc.RpcContext
;
import
org.apache.dubbo.rpc.cluster.router.address.Address
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
/**
* dubbo指定ip调用测试类
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
public
class
DubboRpcTest
{
/*
* 解决log日志依赖冲突问题
*/
static
{
System
.
setProperty
(
"nacos.logging.default.config.enabled"
,
"false"
);
}
/*
* 指定ip调用,router=address;
* injvm = false要设置成false,否则会调用到本地提供者
*/
@DubboReference
(
injvm
=
false
,
interfaceClass
=
RouterSendService
.
class
,
parameters
=
{
"router"
,
"address"
})
private
RouterSendService
routerSendService
;
@Test
public
void
test
()
{
int
i
=
0
;
WsResponse
wsResponse
=
new
WsResponse
();
wsResponse
.
setCmd
(
i
);
wsResponse
.
setCode
(
200
);
wsResponse
.
setMsg
(
"i="
+
i
);
wsResponse
.
setData
(
"hihi"
);
wsResponse
.
setReqId
(
"123"
);
String
msgJson
=
JsonUtils
.
encodeJson
(
wsResponse
);
// 根据provider的ip,port创建Address实例
Address
address
=
new
Address
(
"192.168.1.51"
,
20881
);
RpcContext
.
getContext
().
setObjectAttachment
(
"address"
,
address
);
routerSendService
.
sendMsgRemote
(
123L
,
1
,
msgJson
);
}
}
config/src/main/resources/config/bootstrap.yml
0 → 100644
View file @
0c3334dd
spring
:
profiles
:
active
:
@
profileActive@
---
spring
:
profiles
:
dev
cloud
:
nacos
:
discovery
:
server-addr
:
192.168.1.89:8848
userName
:
"
nacos"
password
:
"
nacos"
config
:
server-addr
:
192.168.1.89:8848
userName
:
"
nacos"
password
:
"
nacos"
file-extension
:
yaml
---
spring
:
profiles
:
test
cloud
:
nacos
:
discovery
:
server-addr
:
localhost:8848
userName
:
"
nacos"
password
:
"
nacos"
config
:
server-addr
:
localhost:8848
userName
:
"
nacos"
password
:
"
nacos"
file-extension
:
yaml
---
spring
:
profiles
:
prod
cloud
:
nacos
:
discovery
:
server-addr
:
localhost:8848
userName
:
"
nacos"
password
:
"
nacos"
config
:
server-addr
:
localhost:8848
userName
:
"
nacos"
password
:
"
nacos"
file-extension
:
yaml
\ No newline at end of file
core/src/main/java/com/wecloud/im/ws/sender/ChannelSender.java
View file @
0c3334dd
package
com
.
wecloud
.
im
.
ws
.
sender
;
package
com
.
wecloud
.
im
.
ws
.
sender
;
import
com.wecloud.im.executor.SendMsgThreadPool
;
import
com.wecloud.im.executor.SendMsgThreadPool
;
import
com.wecloud.utils.GetIpUtils
;
import
com.wecloud.im.router.RouterSendService
;
import
com.wecloud.im.router.RouterSendService
;
import
com.wecloud.im.ws.cache.UserStateCacheManager
;
import
com.wecloud.im.ws.cache.UserStateCacheManager
;
import
com.wecloud.im.ws.manager.ChannelManager
;
import
com.wecloud.im.ws.manager.ChannelManager
;
...
@@ -9,6 +8,7 @@ import com.wecloud.im.ws.model.ClientInfo;
...
@@ -9,6 +8,7 @@ import com.wecloud.im.ws.model.ClientInfo;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.model.WsResponse
;
import
com.wecloud.im.ws.model.redis.ClientChannelInfo
;
import
com.wecloud.im.ws.model.redis.ClientChannelInfo
;
import
com.wecloud.im.ws.model.request.ReceiveVO
;
import
com.wecloud.im.ws.model.request.ReceiveVO
;
import
com.wecloud.utils.GetIpUtils
;
import
com.wecloud.utils.JsonUtils
;
import
com.wecloud.utils.JsonUtils
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiCode
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
import
io.geekidea.springbootplus.framework.common.api.ApiResult
;
...
@@ -38,7 +38,11 @@ public class ChannelSender {
...
@@ -38,7 +38,11 @@ public class ChannelSender {
@Autowired
@Autowired
private
UserStateCacheManager
userStateCacheManager
;
private
UserStateCacheManager
userStateCacheManager
;
@DubboReference
(
parameters
=
{
"router"
,
"address"
})
/*
* 指定ip调用,router=address;
* injvm = false要设置成false,否则会调用到本地提供者
*/
@DubboReference
(
injvm
=
false
,
interfaceClass
=
RouterSendService
.
class
,
parameters
=
{
"router"
,
"address"
})
private
RouterSendService
routerSendService
;
private
RouterSendService
routerSendService
;
/**
/**
...
@@ -104,6 +108,8 @@ public class ChannelSender {
...
@@ -104,6 +108,8 @@ public class ChannelSender {
batchSendMsgLocal
(
toClientIdAndPlatforms
,
msgJson
);
batchSendMsgLocal
(
toClientIdAndPlatforms
,
msgJson
);
}
else
{
}
else
{
String
msgJson
=
JsonUtils
.
encodeJson
(
responseModel
);
String
msgJson
=
JsonUtils
.
encodeJson
(
responseModel
);
// dubbo指定ip调用
Address
address
=
new
Address
(
toIp
,
20881
);
Address
address
=
new
Address
(
toIp
,
20881
);
RpcContext
.
getContext
().
setObjectAttachment
(
"address"
,
address
);
RpcContext
.
getContext
().
setObjectAttachment
(
"address"
,
address
);
routerSendService
.
batchSendMsgRemote
(
toClientIdAndPlatforms
,
msgJson
);
routerSendService
.
batchSendMsgRemote
(
toClientIdAndPlatforms
,
msgJson
);
...
@@ -139,6 +145,7 @@ public class ChannelSender {
...
@@ -139,6 +145,7 @@ public class ChannelSender {
// RpcContext.getContext().set("ip", channelInfo.getLanIp());
// RpcContext.getContext().set("ip", channelInfo.getLanIp());
// 根据provider的ip,port创建Address实例
// 根据provider的ip,port创建Address实例
for
(
ClientChannelInfo
clientChannelInfo
:
channelInfoEntry
.
getValue
())
{
for
(
ClientChannelInfo
clientChannelInfo
:
channelInfoEntry
.
getValue
())
{
// dubbo指定ip调用
Address
address
=
new
Address
(
clientChannelInfo
.
getLanIp
(),
20881
);
Address
address
=
new
Address
(
clientChannelInfo
.
getLanIp
(),
20881
);
RpcContext
.
getContext
().
setObjectAttachment
(
"address"
,
address
);
RpcContext
.
getContext
().
setObjectAttachment
(
"address"
,
address
);
routerSendService
.
sendMsgRemote
(
toClientId
,
clientChannelInfo
.
getPlatform
(),
msgJson
);
routerSendService
.
sendMsgRemote
(
toClientId
,
clientChannelInfo
.
getPlatform
(),
msgJson
);
...
...
pom.xml
View file @
0c3334dd
...
@@ -343,60 +343,55 @@
...
@@ -343,60 +343,55 @@
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo-spring-boot-starter
</artifactId>
<artifactId>
dubbo-spring-boot-starter
</artifactId>
<version>
${dubbo.version}
</version>
<version>
${dubbo.version}
</version>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba.spring
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
spring-context-support
</artifactId>
<artifactId>
dubbo
</artifactId>
<version>
1.0.11
</version>
<version>
${dubbo.version}
</version>
</dependency>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.dubbo</groupId>-->
<!-- <artifactId>dubbo</artifactId>-->
<!-- <version>${dubbo.version}</version>-->
<!-- </dependency>-->
<dependency>
<dependency>
<groupId>
org.apache.dubbo
</groupId>
<groupId>
org.apache.dubbo
</groupId>
<artifactId>
dubbo-registry-nacos
</artifactId>
<artifactId>
dubbo-registry-nacos
</artifactId>
<version>
${dubbo.version}
</version>
<version>
${dubbo.version}
</version>
</dependency>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.alibaba.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>-->
<!-- <version>2.2.5.RELEASE</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <groupId>com.alibaba.spring</groupId>-->
<!-- <artifactId>spring-context-support</artifactId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
<artifactId>
spring-cloud-starter-alibaba-nacos-discovery
</artifactId>
<version>
2.2.5.RELEASE
</version>
<version>
2.2.5.RELEASE
</version>
<exclusions>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-logging
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
com.alibaba.cloud
</groupId>
<artifactId>
spring-cloud-starter-alibaba-nacos-config
</artifactId>
<version>
2.2.5.RELEASE
</version>
<exclusions>
<!-- 排除自带的logback依赖 -->
<exclusion>
<exclusion>
<groupId>
com.alibaba.spring
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-
context-support
</artifactId>
<artifactId>
spring-
boot-starter-logging
</artifactId>
</exclusion>
</exclusion>
</exclusions>
</exclusions>
</dependency>
</dependency>
<!-- rabbitmq -->
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-starter-amqp</artifactId>-->
<!-- </dependency>-->
<dependency>
<dependency>
<groupId>
net.logstash.logback
</groupId>
<groupId>
net.logstash.logback
</groupId>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment