Java Code Examples for org.springframework.jms.config.MethodJmsListenerEndpoint

Following code examples demonstrate how to use org.springframework.jms.config.MethodJmsListenerEndpointfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.jms.config.MethodJmsListenerEndpointand various code implementation of this class.

    public DefaultMessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint) {
        DefaultMessageListenerContainer listenerContainer = super.createListenerContainer(endpoint);

        if (endpoint instanceof MethodJmsListenerEndpoint && listenerContainer instanceof CircuitBreakerAwareMessageListenerContainer) {
            MethodJmsListenerEndpoint mle = (MethodJmsListenerEndpoint) endpoint;
            CircuitBreakerAwareJmsListener declaredAnnotation = mle.getMethod().getDeclaredAnnotation(CircuitBreakerAwareJmsListener.class);
            if (declaredAnnotation != null) {
                String[] strings = declaredAnnotation.hystrixCommandKeys();
                if (strings != null) {
                    CircuitBreakerAwareMessageListenerContainer container = (CircuitBreakerAwareMessageListenerContainer) listenerContainer;
                    container.setHystrixCommandKeys(Arrays.asList(strings));
                    container.setPermitsPerSecond(declaredAnnotation.permitsPerSecond());
                }
            }
        }
        return listenerContainer;
    } 


	public void simpleMessageListener() {
		ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
				Config.class, SimpleMessageListenerTestBean.class);

		JmsListenerContainerTestFactory factory = context.getBean(JmsListenerContainerTestFactory.class);
		assertEquals("One container should have been registered", 1, factory.getListenerContainers().size());
		MessageListenerTestContainer container = factory.getListenerContainers().get(0);

		JmsListenerEndpoint endpoint = container.getEndpoint();
		assertEquals("Wrong endpoint type", MethodJmsListenerEndpoint.class, endpoint.getClass());
		MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) 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());
		assertTrue("Should have been stopped " + container, container.isStopped());
	} 

  private JmsListenerEndpoint replaceMethodJmsListenerEndpoint(MethodJmsListenerEndpoint original) {
    MethodJmsListenerEndpoint replacement = new TracingMethodJmsListenerEndpoint();

    replacement.setBean(original.getBean());
    replacement.setMethod(original.getMethod());
    replacement.setMostSpecificMethod(original.getMostSpecificMethod());
    MessageHandlerMethodFactory messageHandlerMethodFactory = registrar
        .getMessageHandlerMethodFactory();
    if (messageHandlerMethodFactory == null) {
      messageHandlerMethodFactory = createDefaultJmsHandlerMethodFactory();
    }
    replacement.setMessageHandlerMethodFactory(messageHandlerMethodFactory);
    replacement.setBeanFactory(beanFactory);
    replacement.setId(original.getId());
    replacement.setDestination(original.getDestination());
    replacement.setSelector(original.getSelector());
    replacement.setSubscription(original.getSubscription());
    replacement.setConcurrency(original.getConcurrency());

    return replacement;
  } 

    public DefaultMessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint) {
        DefaultMessageListenerContainer container = super.createListenerContainer(endpoint);
        MethodJmsListenerEndpoint methodEndpoint = (MethodJmsListenerEndpoint) endpoint;
        container.setClientId(genClientId(methodEndpoint));
        return container;
    } 

        if (endpoint instanceof MethodJmsListenerEndpoint) {
            MethodJmsListenerEndpointAdapter methodEndpoint = new MethodJmsListenerEndpointAdapter(
                    (MethodJmsListenerEndpoint) endpoint, messageHandlerMethodFactory);
            methodEndpoint.setBeanFactory(beanFactory);
            jmsListenerEndpoint = methodEndpoint;
        } 

	protected MethodJmsListenerEndpoint createMethodJmsListenerEndpoint() {
		System.out.println("##### createMethodJmsListenerEndpoint");
		return new MyMethodJmsListenerEndpoint();
	} 

Advertisement
Javadoc
A JmsListenerEndpoint providing the method to invoke to process an incoming message for this endpoin

t. @author Stephane Nicoll @author Juergen Hoeller @since 4.1

Read More
Advertisement