Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Spring云流测试进行错误测试_Spring_Spring Cloud_Spring Test_Spring Cloud Stream - Fatal编程技术网

使用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