搭配使用
logback日志配置:
https://blog.csdn.net/a755199443/article/details/92208902
Eureka单机服务端配置:
https://blog.csdn.net/a755199443/article/details/92579936
Eureka服务端集群配置:
https://blog.csdn.net/a755199443/article/details/92620273
linux部署Eureka的服务端集群:
https://blog.csdn.net/a755199443/article/details/92637977
消息驱动的消息发送者配置:
https://blog.csdn.net/a755199443/article/details/93716471
消息分组配置:
https://blog.csdn.net/a755199443/article/details/93743806
pom文件配置
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.13.RELEASE</version>
<relativePath />
</parent>
<groupId>com.zzw</groupId>
<artifactId>stream_sender</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
全局配置文件
文件名:application.properties
spring.application.name=stream_reciver
server.port=9051
#设置服务注册中心地址,指向另一个注册中心
eureka.client.serviceUrl.defaultZone=http://user:123456@eureka1:8761/eureka/,http://user:123456@eureka2:8761/eureka/
#rebbitmq 链接信息
spring.rabbitmq.host=192.168.110.129
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=123456
spring.rabbitmq.virtualHost=/
消息接收接口
和启动类在同一级目录下
文件名:IReceiveService.java
@Output注解的值应与消息接收者@Input注解中的值一致
public interface IReceiveService {
@Input("csdn-exchange")
SubscribableChannel receive();
}
接口的实现类
和启动类在同一级目录下
注意要加上@EnableBinding(value={IReceiveService.class}) 注解和消息发送接口做绑定
文件名:ReceiveService.java
@Service
@EnableBinding({IReceiveService.class})
public class ReceiveService {
//指定处理哪个队列的消息
@StreamListener("csdn-exchange")
public void onReceive(byte[] msg){
//处理消息
System.out.println("Receiver: "+new String(msg));
}
}
启动类
文件名:StreamSenderApplication.properties注意要加上@EnableBinding(value={IReceiveService.class}) 注解和消息发送接口做绑定
@SpringBootApplication
@EnableEurekaClient
@EnableBinding(value={IReceiveService.class})
public class StreamReceiveApplication {
public static void main(String[] args) {
SpringApplication.run(StreamReceiveApplication.class, args);
}
}