Browse Source

🍱 增加cloud-stream-rabbitmq的example

test
smallchill 5 years ago
parent
commit
54554e2fe8
  1. 2
      blade-common/src/main/java/org/springblade/common/constant/LauncherConstant.java
  2. 37
      blade-example/blade-mq-stream/pom.xml
  3. 35
      blade-example/blade-mq-stream/src/main/java/org/springblade/example/mq/stream/StreamApplication.java
  4. 25
      blade-example/blade-mq-stream/src/main/java/org/springblade/example/mq/stream/handler/StreamHandler.java
  5. 26
      blade-example/blade-mq-stream/src/main/resources/application.yml
  6. 33
      blade-example/blade-mq-stream/src/test/java/org/springblade/example/mq/stream/StreamTest.java
  7. 1
      blade-example/pom.xml

2
blade-common/src/main/java/org/springblade/common/constant/LauncherConstant.java

@ -100,7 +100,7 @@ public interface LauncherConstant {
/**
* rocket
*/
String APPLICATION_ROCKET_NAME = APPLICATION_NAME_PREFIX + "rocket";
String APPLICATION_STREAM_NAME = APPLICATION_NAME_PREFIX + "stream";
/**
* 动态获取nacos地址

37
blade-example/blade-mq-stream/pom.xml

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
<artifactId>blade-example</artifactId>
<groupId>org.springblade</groupId>
<version>2.2.2.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>blade-mq-stream</artifactId>
<name>${project.artifactId}</name>
<version>${bladex.project.version}</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-launch</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-tool</artifactId>
</dependency>
<dependency>
<groupId>org.springblade</groupId>
<artifactId>blade-core-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
</dependencies>
</project>

35
blade-example/blade-mq-stream/src/main/java/org/springblade/example/mq/stream/StreamApplication.java

@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.example.mq.stream;
import org.springblade.common.constant.LauncherConstant;
import org.springblade.core.launch.BladeApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* StreamApplication
*
* @author Chill
*/
@SpringBootApplication
public class StreamApplication {
public static void main(String[] args) {
BladeApplication.run(LauncherConstant.APPLICATION_STREAM_NAME, StreamApplication.class, args);
}
}

25
blade-example/blade-mq-stream/src/main/java/org/springblade/example/mq/stream/handler/StreamHandler.java

@ -0,0 +1,25 @@
package org.springblade.example.mq.stream.handler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.stereotype.Component;
/**
* StreamHandler
*
* @author Chill
*/
@Slf4j
@Component
@EnableBinding(Processor.class)
public class StreamHandler {
@StreamListener(Processor.INPUT)
public void process(String message) {
log.info("hello : " + message);
System.out.println("hello : " + message);
}
}

26
blade-example/blade-mq-stream/src/main/resources/application.yml

@ -0,0 +1,26 @@
server:
port: 8603
spring:
cloud:
stream:
bindings:
input:
#要和output的destination一致, 这样才能将队列和写入消息的exchange关联起来
destination: queue.log.messages
binder: rabbit-stream
group: logMessageConsumers
output:
destination: queue.log.messages
binder: rabbit-stream
binders:
rabbit-stream:
type: rabbit
environment:
spring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
virtual-host: /

33
blade-example/blade-mq-stream/src/test/java/org/springblade/example/mq/stream/StreamTest.java

@ -0,0 +1,33 @@
package org.springblade.example.mq.stream;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springblade.core.test.BladeBootTest;
import org.springblade.core.test.BladeSpringRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.messaging.support.MessageBuilder;
/**
* StreamTest
*
* @author Chill
*/
@RunWith(BladeSpringRunner.class)
@SpringBootTest(classes = StreamApplication.class)
@BladeBootTest(appName = "blade-stream", profile = "test", enableLoader = true)
public class StreamTest {
@Autowired
private Processor pipe;
/**
* 测试直接模式发送
*/
@Test
public void sendDirect() {
pipe.output().send(MessageBuilder.withPayload("message").build());
}
}

1
blade-example/pom.xml

@ -21,6 +21,7 @@
<module>blade-easypoi</module>
<module>blade-mq-kafka</module>
<module>blade-mq-rabbit</module>
<module>blade-mq-stream</module>
<module>blade-seata-order</module>
<module>blade-seata-storage</module>
<module>blade-websocket</module>

Loading…
Cancel
Save