我正在使用springboot2.4.2版本,并使用 @InboundChannelAdapter
.
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.annotation.InboundChannelAdapter;
@EnableBinding(value = Source.class)
public class TransactionPublisher {
@InboundChannelAdapter(channel = Source.OUTPUT)
public String sendTransactionDetails() {
return "{name:\"T1\", amount: \"1000\", transactionFor : \"Purchase\"}";
}
}
rabbitmqreceiverapplication.java文件
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.cloud.stream.messaging.Sink;
@EnableBinding(value = Sink.class)
@SpringBootApplication
public class RabbitmqReceiverApplication {
public static void main(String[] args) {
SpringApplication.run(RabbitmqReceiverApplication.class, args);
}
@StreamListener(Sink.INPUT)
public void log(String message) {
System.out.println(message);
}
}
还有什么选择呢?那么如何重构上述代码呢?很多事情都发生在节奏变得难以理解什么来了什么去了?
1条答案
按热度按时间lnxxn5zx1#
请参阅文档。
e、 在消费者方面。。。
绑定名称为
log-in-0
.在制作人方面,这是一个
Supplier<String>
具有绑定名称的beansendTransactionDetails-out-0
.