|
|
|
@ -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);
|
|
|
|
|
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 (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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|