消息订阅、发送成功
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package top.fjy8018.producer;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
import org.springframework.cloud.stream.annotation.Output;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.fjy8018.consumer.common.MySource;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author F嘉阳
|
||||
* @date 2018-10-08 17:57
|
||||
*/
|
||||
@RestController
|
||||
@EnableBinding(MySource.class)
|
||||
public class Producer {
|
||||
|
||||
@Autowired
|
||||
@Output(MySource.OUTPUT)
|
||||
private MessageChannel channel;
|
||||
|
||||
@RequestMapping("/send")
|
||||
public String send() {
|
||||
channel.send(MessageBuilder.withPayload(new Date()).build());
|
||||
return "success";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package top.fjy8018.producer;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ProducerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ProducerApplication.class, args);
|
||||
}
|
||||
}
|
||||
12
producer/producer-server/src/main/resources/application.yml
Normal file
12
producer/producer-server/src/main/resources/application.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
spring:
|
||||
rabbitmq:
|
||||
host: docker-1.fjy8018.cn
|
||||
username: cms
|
||||
password: cms-mq-admin
|
||||
cloud:
|
||||
stream:
|
||||
bindings:
|
||||
output:
|
||||
destination: my-test-channel
|
||||
server:
|
||||
port: 8082
|
||||
Reference in New Issue
Block a user