Example usage for org.springframework.jms.listener DefaultMessageListenerContainer setSubscriptionShared

List of usage examples for org.springframework.jms.listener DefaultMessageListenerContainer setSubscriptionShared

Introduction

In this page you can find the example usage for org.springframework.jms.listener DefaultMessageListenerContainer setSubscriptionShared.

Prototype

public void setSubscriptionShared(boolean subscriptionShared) 

Source Link

Document

Set whether to make the subscription shared.

Usage

From source file:ch.algotrader.event.TopicEventDumper.java

public static void main(String... args) throws Exception {

    SingleConnectionFactory jmsActiveMQFactory = new SingleConnectionFactory(
            new ActiveMQConnectionFactory("tcp://localhost:61616"));
    jmsActiveMQFactory.afterPropertiesSet();
    jmsActiveMQFactory.resetConnection();

    ActiveMQTopic topic = new ActiveMQTopic(">");

    DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer();
    messageListenerContainer.setDestination(topic);
    messageListenerContainer.setConnectionFactory(jmsActiveMQFactory);
    messageListenerContainer.setSubscriptionShared(false);
    messageListenerContainer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER);

    messageListenerContainer.setMessageListener((MessageListener) message -> {
        try {/* w w  w .  ja  va2 s .  c om*/
            Destination destination = message.getJMSDestination();
            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                System.out.println(destination + " -> " + textMessage.getText());
            } else if (message instanceof BytesMessage) {
                BytesMessage bytesMessage = (BytesMessage) message;
                byte[] bytes = new byte[(int) bytesMessage.getBodyLength()];
                bytesMessage.readBytes(bytes);
                System.out.println(destination + " -> " + new String(bytes, Charsets.UTF_8));
            }
        } catch (JMSException ex) {
            throw new UnrecoverableCoreException(ex);
        }
    });

    messageListenerContainer.initialize();
    messageListenerContainer.start();

    System.out.println("Dumping messages from all topics");

    Runtime.getRuntime().addShutdownHook(new Thread(messageListenerContainer::stop));

    Thread.sleep(Long.MAX_VALUE);
}

From source file:com.kinglcc.spring.jms.core.listener.DynamicJmsListenerContainerFactory.java

@Override
public DefaultMessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint) {
    DefaultMessageListenerContainer instance = super.createListenerContainer(endpoint);
    instance.setClientId(resolveClientId(endpoint));
    if (endpoint instanceof AbstractJmsListenerEndpoint) {
        AbstractJmsListenerEndpoint jmsEndpoint = ((AbstractJmsListenerEndpoint) endpoint);
        DestinationType destinationType = DestinationType.asDestinationType(jmsEndpoint.getDestination());
        instance.setPubSubDomain(destinationType.isPubSubDomain());
        instance.setSubscriptionDurable(destinationType.isSubscriptionDurable());
        instance.setSubscriptionShared(destinationType.isSubscriptionShared());
    }/*from ww  w .j a  v a2 s  . co m*/
    endpoint.setupListenerContainer(instance);

    return instance;
}