使用Spring云流测试进行错误测试
我们正在使用使用Spring云流测试进行错误测试,spring,spring-cloud,spring-test,spring-cloud-stream,Spring,Spring Cloud,Spring Test,Spring Cloud Stream,我们正在使用springcloudstream来管理应用程序之间的消息 我们有自定义绑定: public interface InboundChannels { String TASKS = "domainTasksInboundChannel"; String EVENTS = "eventsInboundChannel"; @Input(TASKS) SubscribableChannel tasks(); @Input(EVENTS) Subscribable
springcloudstream
来管理应用程序之间的消息
我们有自定义绑定:
public interface InboundChannels {
String TASKS = "domainTasksInboundChannel";
String EVENTS = "eventsInboundChannel";
@Input(TASKS)
SubscribableChannel tasks();
@Input(EVENTS)
SubscribableChannel events();
}
public interface OutboundChannels {
String TASKS = "domainTasksOutboundChannel";
String EVENTS = "eventsOutboundChannel";
@Output(TASKS)
MessageChannel tasks();
@Output(EVENTS)
MessageChannel events();
}
有些处理器使用任务并生成事件:
@EnableBinding({InboundChannels.class, OutboundChannels.class})
public class TasksProcessor {
public TasksProcessor(
UserService userService,
@Qualifier(OutboundChannels.EVENTS) MessageChannel eventsChannel
) {
this.userService = userService;
this.eventsChannel = eventsChannel;
}
@StreamListener(value = TASKS, condition = "headers['" + TYPE + "']=='" + CREATE_USER + "'")
public void createUser(Message<User> message) {
final User user = message.getPayload();
userService.save(user)
.subscribe(created -> {
Message<User> successMessage = fromMessage(message, Events.USER_CREATED, created).build();
eventsChannel.send(successMessage);
});
}
}
应用程序属性
##
# Spring AMQP configuration
##
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin
# Events channels
spring.cloud.stream.bindings.eventsOutboundChannel.destination=events
spring.cloud.stream.bindings.eventsInboundChannel.destination=events
spring.cloud.stream.bindings.domainTasksOutboundChannel.destination=domainTasks
spring.cloud.stream.bindings.domainTasksInboundChannel.destination=domainTasks
spring.cloud.stream.bindings.userTasksInboundChannel.group=domainServiceInstances
spring.cloud.stream.bindings.eventsInboundChannel.group=domainServiceInstances
但是我们得到了这个错误:
java.lang.IllegalArgumentException: Channel [eventsInboundChannel] was not bound by class org.springframework.cloud.stream.test.binder.TestSupportBinder
我们做错了什么?在.subscribe()
中,您执行事件annel.send(成功消息)代码>,其中eventsChannel
来自OutboundChannels.EVENTS
,但您在测试用例中尝试执行的操作类似于inboundChannels.EVENTS()
。看起来你并没有把这个频道绑定到任何地方
我确信如果您使用outboundChannels.events()
的话,这对您来说是可行的。它绑定在这里:@EnableBinding({InboundChannels.class,outboundChannels.class})
,我添加了我的应用程序.properties
以便您可以查看一下。嗨,您找到了错误还是找到了有效的解决方法?
java.lang.IllegalArgumentException: Channel [eventsInboundChannel] was not bound by class org.springframework.cloud.stream.test.binder.TestSupportBinder