Example usage for org.springframework.jms.core JmsTemplate JmsTemplate

List of usage examples for org.springframework.jms.core JmsTemplate JmsTemplate

Introduction

In this page you can find the example usage for org.springframework.jms.core JmsTemplate JmsTemplate.

Prototype

public JmsTemplate(ConnectionFactory connectionFactory) 

Source Link

Document

Create a new JmsTemplate, given a ConnectionFactory.

Usage

From source file:camelpoc.AmqBrokerTest.java

@Test
public void shouldCreateAmqBroker() throws Exception {
    // Given//from  w  w  w  .j a  v a  2  s .c om
    ServiceProxy<FabricService> fabricService = ServiceProxy.createServiceProxy(bundleContext,
            FabricService.class);

    String message = "message";
    String queue = "queue";
    System.err.println(executeCommand("fabric:create -n"));
    containers = create(fabricService).withName("router-container").withProfiles("mq-amq")
            .assertProvisioningResult().build();
    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("admin", "admin",
            "discovery:(fabric:default)");
    JmsTemplate jms = new JmsTemplate(connectionFactory);

    // When
    jms.convertAndSend(queue, message);
    String receivedMessage = (String) jms.receiveAndConvert(queue);

    // Then
    assertEquals(message, receivedMessage);
}

From source file:org.apache.servicemix.jms.AbstractJmsTestSupport.java

protected void createJmsTemplate() throws Exception {
    jmsTemplate = new JmsTemplate(new PooledConnectionFactory(connectionFactory));
}

From source file:com.athena.dolly.common.core.ActiveMQPlaygroundConfiguration.java

private JmsTemplate jmsTemplate() {
    return new JmsTemplate(connectionFactory());
}

From source file:com.kinglcc.spring.jms.config.JmsAnnotationAtuoConfiguration.java

@Bean
@ConditionalOnMissingBean/*from w  ww .  j ava 2s . c  o m*/
public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory) {
    JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
    jmsTemplate.setPubSubDomain(this.properties.isPubSubDomain());
    if (this.destinationResolver != null) {
        jmsTemplate.setDestinationResolver(this.destinationResolver);
    }
    jmsTemplate.setMessageConverter(messageConverter);
    return jmsTemplate;
}

From source file:org.addsimplicity.anicetus.io.jms.JMSDeliveryAdapter.java

/**
 * Called by Spring once all properties have been set. This method will
 * establish the connection to the JMS broker.
 *///from   www. java2s. c o  m
public void afterPropertiesSet() throws Exception {
    BlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(m_maxDeliveryQueue);
    m_executor = new ThreadPoolExecutor(1, m_maxDeliveryThreads, 60l, TimeUnit.SECONDS, q,
            new DeliveryThreadFactory(), m_rejectionHandler);

    m_template = new JmsTemplate(m_connectionFactory);
    m_template.setDefaultDestination(m_destination);
    m_template.setMessageConverter(m_messageConverter);
}

From source file:terrastore.event.impl.ActiveMQEventBus.java

public ActiveMQEventBus(List<EventListener> eventListeners, ActionExecutor actionExecutor, String broker)
        throws Exception {
    LOG.info("Configuring event bus: {}", this.getClass().getName());
    this.eventListeners = eventListeners;
    this.actionExecutor = actionExecutor;
    this.jmsConnectionFactory = new PooledConnectionFactory(broker);
    this.producer = new JmsTemplate(jmsConnectionFactory);
    this.enabled = this.eventListeners.size() > 0;
    initListeners(this.eventListeners);
    initConsumers(broker);//from  w w w.jav a2  s.  c o m
}

From source file:org.apache.servicemix.audit.async.AbstractJmsExchangeListener.java

public void afterPropertiesSet() throws Exception {
    if (factory == null) {
        throw new IllegalStateException(
                "Unable to initialize JMS ExchangeListener -- no ConnectionFactory set");
    }//w  w  w  .  j ava  2  s . c  o  m
    container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(factory);
    container.setDestinationName(getDestinationName());
    container.setMessageListener(new MessageListener() {

        @SuppressWarnings("unchecked")
        public void onMessage(Message message) {
            ObjectMessage om = (ObjectMessage) message;
            try {
                T object = (T) om.getObject();
                switch (Event.valueOf(om.getStringProperty(EVENT))) {
                case Sent:
                    onSent(object);
                case Accepted:
                    onAccepted(object);
                }
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

    });
    container.afterPropertiesSet();
    container.setConcurrentConsumers(10);
    container.start();

    jmsTemplate = new JmsTemplate(factory);
    jmsTemplate.setDefaultDestinationName(getDestinationName());
}

From source file:org.springsource.greenbeans.examples.edawithspring.etailer.store.StoreConfiguration.java

@Bean
public JmsTemplate jmsTemplate() {
    JmsTemplate jmsTemplate = new JmsTemplate(this.connectionFactory());
    jmsTemplate.setSessionTransacted(true);
    return jmsTemplate;
}

From source file:com.oneops.daq.jms.SensorPublisher.java

/**
 * Inits the.//from   ww  w .  j a v  a  2  s .c  o m
 *
 * @throws JMSException the jMS exception
 */
public void init() throws JMSException {
    Properties properties = new Properties();
    try {
        properties.load(this.getClass().getResourceAsStream("/sink.properties"));
    } catch (IOException e) {
        logger.error("got: " + e.getMessage());
    }

    user = properties.getProperty("amq.user");
    password = System.getenv("KLOOPZ_AMQ_PASS");

    if (password == null) {
        throw new JMSException("missing KLOOPZ_AMQ_PASS env var");
    }

    AMQConnectorURI connectStringGenerator = new AMQConnectorURI();
    connectStringGenerator.setHost("opsmq");
    connectStringGenerator.setProtocol("tcp");
    connectStringGenerator.setPort(61616);
    connectStringGenerator.setTransport("failover");
    connectStringGenerator.setDnsResolve(true);
    connectStringGenerator.setKeepAlive(true);
    HashMap<String, String> transportOptions = new HashMap<>();
    transportOptions.put("initialReconnectDelay", "1000");
    transportOptions.put("startupMaxReconnectAttempts", mqConnectionStartupRetries);
    transportOptions.put("timeout", mqConnectionTimeout);
    transportOptions.put("useExponentialBackOff", "false");
    connectStringGenerator.setTransportOptions(transportOptions);
    url = connectStringGenerator.build();

    showParameters();

    // Create the connection.
    ActiveMQConnectionFactory amqConnectionFactory = new ActiveMQConnectionFactory(user, password, url);
    amqConnectionFactory.setUseAsyncSend(true);
    PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(amqConnectionFactory);
    pooledConnectionFactory.setMaxConnections(4);
    pooledConnectionFactory.setIdleTimeout(10000);

    for (int i = 0; i < poolsize; i++) {
        JmsTemplate producerTemplate = new JmsTemplate(pooledConnectionFactory);
        producerTemplate.setSessionTransacted(false);
        int shard = i + 1;
        Destination perfin = new org.apache.activemq.command.ActiveMQQueue(queueBase + "-" + shard);
        producerTemplate.setDefaultDestination(perfin);
        producerTemplate.setDeliveryPersistent(false);
        producers[i] = producerTemplate;
    }

}