将消息从我的云春天代码发布到不添加到Rabbitmq队列的rabbitmq,我有一个接收器应用程序创建了Rabbitmq Exchange和Queue,效果很好。 下一个我使用邮递员发布一些参数,此有效负载被发送到通过以下代码发布请求的控制器:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.cloud.task.launcher.TaskLaunchRequest;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;
@Component
@EnableBinding(Source.class)
public class TaskProcessor {
@Autowired
private Source source;
public void publishRequest(String payload) {
String url="maven://com.BBG.spring.task.text:"
+ "BBG-Spring-task-text-Validation:jar:0.0.1-SNAPSHOT";
//arg for this test are string seperated by ,
List<String> input= new ArrayList<String>(Arrays.asList(payload.split(",")));
TaskLaunchRequest request = new TaskLaunchRequest(url,input,null,null,null);
System.out.println("Created task request");
GenericMessage<TaskLaunchRequest> message=new GenericMessage<>(request);
this.source.output().send(message);
}
}
application properties
spring.main.allow-bean-definition-overriding=true
server.port=8082
spring.rabbitmq.broker-url=tcp://127.0.0.1:5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.cloud.stream.bindings.input.destination=tasktopic
logging.level.org.springframework.cloud.task=DEBUG
logging.level.org.springframework.cloud.stream=DEBUG
POM.xml
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.BBG.spring.task.sinc</groupId>
<artifactId>BBG-Spring-task-intake-rabbmq</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>BBG-Spring-task-intake-rabbmq</name>
<description>task in take </description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-task</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-test-support</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository>
</repositories>