Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
open-source
/
glsx-smart-message-channel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 13ecf084
authored
Apr 19, 2021
by
111-PC\111
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[+]pulsar消费服务
1 parent
caf47adc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
src/main/java/cn/com/glsx/consumer/common/MqConsumer.java
src/main/java/cn/com/glsx/consumer/comsumers/TuyaComsumer.java
src/main/java/cn/com/glsx/consumer/common/MqConsumer.java
View file @
13ecf08
...
@@ -25,6 +25,8 @@ public class MqConsumer {
...
@@ -25,6 +25,8 @@ public class MqConsumer {
private
IMessageListener
messageListener
;
private
IMessageListener
messageListener
;
private
String
subscriptionName
;
public
static
MqConsumer
build
()
{
public
static
MqConsumer
build
()
{
return
new
MqConsumer
();
return
new
MqConsumer
();
}
}
...
@@ -38,6 +40,10 @@ public class MqConsumer {
...
@@ -38,6 +40,10 @@ public class MqConsumer {
this
.
accessId
=
accessId
;
this
.
accessId
=
accessId
;
return
this
;
return
this
;
}
}
public
MqConsumer
subscriptionName
(
String
subscriptionName
)
{
this
.
subscriptionName
=
subscriptionName
;
return
this
;
}
public
MqConsumer
accessKey
(
String
accessKey
)
{
public
MqConsumer
accessKey
(
String
accessKey
)
{
this
.
accessKey
=
accessKey
;
this
.
accessKey
=
accessKey
;
...
@@ -75,7 +81,7 @@ public class MqConsumer {
...
@@ -75,7 +81,7 @@ public class MqConsumer {
PulsarClient
client
=
PulsarClient
.
builder
().
serviceUrl
(
serviceUrl
).
allowTlsInsecureConnection
(
true
)
PulsarClient
client
=
PulsarClient
.
builder
().
serviceUrl
(
serviceUrl
).
allowTlsInsecureConnection
(
true
)
.
authentication
(
new
MqAuthentication
(
accessId
,
accessKey
)).
build
();
.
authentication
(
new
MqAuthentication
(
accessId
,
accessKey
)).
build
();
Consumer
consumer
=
client
.
newConsumer
().
topic
(
String
.
format
(
"%s/out/%s"
,
accessId
,
topic
))
Consumer
consumer
=
client
.
newConsumer
().
topic
(
String
.
format
(
"%s/out/%s"
,
accessId
,
topic
))
.
subscriptionName
(
String
.
format
(
"%s-sub"
,
accessId
)).
subscriptionType
(
SubscriptionType
.
Failover
)
.
subscriptionName
(
String
.
format
(
"%s-sub"
,
subscriptionName
)).
subscriptionType
(
SubscriptionType
.
Failover
)
.
deadLetterPolicy
(
DeadLetterPolicy
.
builder
().
maxRedeliverCount
(
maxRedeliverCount
).
build
()).
subscribe
();
.
deadLetterPolicy
(
DeadLetterPolicy
.
builder
().
maxRedeliverCount
(
maxRedeliverCount
).
build
()).
subscribe
();
do
{
do
{
try
{
try
{
...
...
src/main/java/cn/com/glsx/consumer/comsumers/TuyaComsumer.java
View file @
13ecf08
...
@@ -32,12 +32,15 @@ public class TuyaComsumer implements CommandLineRunner {
...
@@ -32,12 +32,15 @@ public class TuyaComsumer implements CommandLineRunner {
@Value
(
"${pulsar.topic}"
)
@Value
(
"${pulsar.topic}"
)
private
String
topic
;
private
String
topic
;
@Value
(
"${pulsar.subscriptionName}"
)
private
String
subscriptionName
;
@Autowired
@Autowired
private
InfoService
infoService
;
private
InfoService
infoService
;
@Override
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
public
void
run
(
String
...
args
)
throws
Exception
{
MqConsumer
mqConsumer
=
MqConsumer
.
build
().
serviceUrl
(
serviceUrl
).
accessId
(
accessId
).
accessKey
(
accessKey
).
topic
(
topic
)
MqConsumer
mqConsumer
=
MqConsumer
.
build
().
serviceUrl
(
serviceUrl
).
accessId
(
accessId
).
accessKey
(
accessKey
).
topic
(
topic
)
.
subscriptionName
(
subscriptionName
)
.
maxRedeliverCount
(
maxRedeliverCount
).
messageListener
(
.
maxRedeliverCount
(
maxRedeliverCount
).
messageListener
(
message
->
{
message
->
{
log
.
info
(
"Message received:"
+
new
String
(
message
.
getData
())
+
",seq="
log
.
info
(
"Message received:"
+
new
String
(
message
.
getData
())
+
",seq="
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment