mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #611 from fangjian0423/binder-dev
[RocketMQ Binder] Support PolledConsumer
This commit is contained in:
@@ -9,6 +9,7 @@ import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@@ -23,6 +24,9 @@ public class RocketMQProduceApplication {
|
||||
|
||||
@Output("output2")
|
||||
MessageChannel output2();
|
||||
|
||||
@Output("output3")
|
||||
MessageChannel output3();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -31,7 +35,12 @@ public class RocketMQProduceApplication {
|
||||
|
||||
@Bean
|
||||
public CustomRunner customRunner() {
|
||||
return new CustomRunner();
|
||||
return new CustomRunner("output1");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CustomRunner customRunner2() {
|
||||
return new CustomRunner("output3");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -40,24 +49,45 @@ public class RocketMQProduceApplication {
|
||||
}
|
||||
|
||||
public static class CustomRunner implements CommandLineRunner {
|
||||
|
||||
private final String bindingName;
|
||||
|
||||
public CustomRunner(String bindingName) {
|
||||
this.bindingName = bindingName;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SenderService senderService;
|
||||
|
||||
@Autowired
|
||||
private MySource mySource;
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
int count = 5;
|
||||
for (int index = 1; index <= count; index++) {
|
||||
String msgContent = "msg-" + index;
|
||||
if (index % 3 == 0) {
|
||||
senderService.send(msgContent);
|
||||
}
|
||||
else if (index % 3 == 1) {
|
||||
senderService.sendWithTags(msgContent, "tagStr");
|
||||
}
|
||||
else {
|
||||
senderService.sendObject(new Foo(index, "foo"), "tagObj");
|
||||
if (this.bindingName.equals("output1")) {
|
||||
int count = 5;
|
||||
for (int index = 1; index <= count; index++) {
|
||||
String msgContent = "msg-" + index;
|
||||
if (index % 3 == 0) {
|
||||
senderService.send(msgContent);
|
||||
}
|
||||
else if (index % 3 == 1) {
|
||||
senderService.sendWithTags(msgContent, "tagStr");
|
||||
}
|
||||
else {
|
||||
senderService.sendObject(new Foo(index, "foo"), "tagObj");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this.bindingName.equals("output3")) {
|
||||
int count = 50;
|
||||
for (int index = 1; index <= count; index++) {
|
||||
String msgContent = "pullMsg-" + index;
|
||||
mySource.output3()
|
||||
.send(MessageBuilder.withPayload(msgContent).build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,6 +12,10 @@ spring.cloud.stream.bindings.output2.content-type=application/json
|
||||
spring.cloud.stream.rocketmq.bindings.output2.producer.transactional=true
|
||||
spring.cloud.stream.rocketmq.bindings.output2.producer.group=myTxProducerGroup
|
||||
|
||||
spring.cloud.stream.bindings.output3.destination=pull-topic
|
||||
spring.cloud.stream.bindings.output3.content-type=text/plain
|
||||
spring.cloud.stream.rocketmq.bindings.output3.producer.group=pull-binder-group
|
||||
|
||||
spring.application.name=rocketmq-produce-example
|
||||
|
||||
server.port=28081
|
||||
|
Reference in New Issue
Block a user