7 changed files with 158 additions and 1 deletions
@ -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> |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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); |
||||
} |
||||
|
||||
} |
@ -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: / |
@ -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()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue