@Nullable private String getDefaultReplyToAddress() { Method listenerMethod = getMethod(); if (listenerMethod != null) { SendTo ann = AnnotationUtils.getAnnotation(listenerMethod, SendTo.class); if (ann != null) { String[] destinations = ann.value(); if (destinations.length > 1) { throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" + listenerMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")"); } return destinations.length == 1 ? resolveSendTo(destinations[0]) : ""; } } return null; }
@Nullable private String getDefaultReplyToAddress() { Method listenerMethod = getMethod(); if (listenerMethod != null) { SendTo ann = AnnotationUtils.getAnnotation(listenerMethod, SendTo.class); if (ann != null) { String[] destinations = ann.value(); if (destinations.length > 1) { throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '" + listenerMethod + "' one destination must be set (got " + Arrays.toString(destinations) + ")"); } return destinations.length == 1 ? resolveSendTo(destinations[0]) : ""; } } return null; }
/** * Create a {@link HandlerAdapter} for this listener adapter. * @param messageListener the listener adapter. * @return the handler adapter. */ protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); return new HandlerAdapter(invocableHandlerMethod); }
/** * Create a {@link HandlerAdapter} for this listener adapter. * @param messageListener the listener adapter. * @return the handler adapter. */ protected HandlerAdapter configureListenerAdapter(MessagingMessageListenerAdapter messageListener) { InvocableHandlerMethod invocableHandlerMethod = this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod()); return new HandlerAdapter(invocableHandlerMethod); }
@Test public void simpleMessageListenerWithMixedAnnotations() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( Config.class, SimpleMessageListenerWithMixedAnnotationsTestBean.class); RabbitListenerContainerTestFactory factory = context.getBean(RabbitListenerContainerTestFactory.class); assertEquals("One container should have been registered", 1, factory.getListenerContainers().size()); MessageListenerTestContainer container = factory.getListenerContainers().get(0); RabbitListenerEndpoint endpoint = container.getEndpoint(); assertEquals("Wrong endpoint type", MethodRabbitListenerEndpoint.class, endpoint.getClass()); MethodRabbitListenerEndpoint methodEndpoint = (MethodRabbitListenerEndpoint) endpoint; assertNotNull(methodEndpoint.getBean()); assertNotNull(methodEndpoint.getMethod()); Iterator<String> iterator = ((MethodRabbitListenerEndpoint) endpoint).getQueueNames().iterator(); assertEquals("testQueue", iterator.next()); assertEquals("secondQueue", iterator.next()); SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); methodEndpoint.setupListenerContainer(listenerContainer); assertNotNull(listenerContainer.getMessageListener()); assertTrue("Should have been started " + container, container.isStarted()); context.close(); // Close and stop the listeners assertTrue("Should have been stopped " + container, container.isStopped()); }
@Test public void simpleMessageListener() { ConfigurableApplicationContext context = new AnnotationConfigApplicationContext( Config.class, SimpleMessageListenerTestBean.class); RabbitListenerContainerTestFactory factory = context.getBean(RabbitListenerContainerTestFactory.class); assertEquals("One container should have been registered", 1, factory.getListenerContainers().size()); MessageListenerTestContainer container = factory.getListenerContainers().get(0); RabbitListenerEndpoint endpoint = container.getEndpoint(); assertEquals("Wrong endpoint type", MethodRabbitListenerEndpoint.class, endpoint.getClass()); MethodRabbitListenerEndpoint methodEndpoint = (MethodRabbitListenerEndpoint) endpoint; assertNotNull(methodEndpoint.getBean()); assertNotNull(methodEndpoint.getMethod()); SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer(); methodEndpoint.setupListenerContainer(listenerContainer); assertNotNull(listenerContainer.getMessageListener()); assertTrue("Should have been started " + container, container.isStarted()); context.close(); // Close and stop the listeners assertTrue("Should have been stopped " + container, container.isStopped()); }