Search in sources :

Example 96 with MessageProducer

use of javax.jms.MessageProducer in project quickstarts by jboss-switchyard.

the class JMSClient method sendToHornetQ.

private static void sendToHornetQ() throws Exception {
    HornetQMixIn hqMixIn = new HornetQMixIn(false).setUser(HQ_USER).setPassword(HQ_PASSWD);
    hqMixIn.initialize();
    Session session = null;
    try {
        session = hqMixIn.createJMSSession();
        final MessageProducer producer = session.createProducer(HornetQMixIn.getJMSQueue(QUEUE_NAME));
        Message message = hqMixIn.createJMSMessageFromResource(MESSAGE_PAYLOAD);
        producer.send(message);
        System.out.println("Message sent. Please see server console output");
    } finally {
        hqMixIn.uninitialize();
    }
}
Also used : Message(javax.jms.Message) MessageProducer(javax.jms.MessageProducer) HornetQMixIn(org.switchyard.component.test.mixins.hornetq.HornetQMixIn) Session(javax.jms.Session)

Example 97 with MessageProducer

use of javax.jms.MessageProducer in project camel by apache.

the class Jms2ObjectFactory method createMessageProducer.

@Override
public MessageProducer createMessageProducer(Session session, Destination destination, boolean persistent, long ttl) throws Exception {
    MessageProducer messageProducer = session.createProducer(destination);
    messageProducer.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
    if (ttl > 0) {
        messageProducer.setTimeToLive(ttl);
    }
    return messageProducer;
}
Also used : MessageProducer(javax.jms.MessageProducer)

Example 98 with MessageProducer

use of javax.jms.MessageProducer in project camel by apache.

the class SjmsProducer method doCreateProducerModel.

protected MessageProducerResources doCreateProducerModel(Session session) throws Exception {
    MessageProducerResources answer;
    try {
        MessageProducer messageProducer = getEndpoint().getJmsObjectFactory().createMessageProducer(session, getEndpoint());
        answer = new MessageProducerResources(session, messageProducer, getCommitStrategy());
    } catch (Exception e) {
        log.error("Unable to create the MessageProducer", e);
        throw e;
    }
    return answer;
}
Also used : MessageProducer(javax.jms.MessageProducer)

Example 99 with MessageProducer

use of javax.jms.MessageProducer in project camel by apache.

the class Jms11ObjectFactory method createMessageProducer.

public MessageProducer createMessageProducer(Session session, Destination destination, boolean persistent, long ttl) throws Exception {
    MessageProducer messageProducer = session.createProducer(destination);
    messageProducer.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
    if (ttl > 0) {
        messageProducer.setTimeToLive(ttl);
    }
    return messageProducer;
}
Also used : MessageProducer(javax.jms.MessageProducer)

Example 100 with MessageProducer

use of javax.jms.MessageProducer in project pinpoint by naver.

the class ActiveMQClientITBase method testTopicPull.

@Test
public void testTopicPull() throws Exception {
    // Given
    final String testTopicName = "TestPullTopic";
    final ActiveMQTopic testTopic = new ActiveMQTopic(testTopicName);
    final String testMessage = "Hello World for Topic!";
    // create producer
    ActiveMQSession producerSession = ActiveMQClientITHelper.createSession(getProducerBrokerName(), getProducerBrokerUrl());
    MessageProducer producer = new MessageProducerBuilder(producerSession, testTopic).waitTillStarted().build();
    final TextMessage expectedTextMessage = producerSession.createTextMessage(testMessage);
    // create 2 consumers
    ActiveMQSession consumer1Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer1 = new MessageConsumerBuilder(consumer1Session, testTopic).waitTillStarted().build();
    ActiveMQSession consumer2Session = ActiveMQClientITHelper.createSession(getConsumerBrokerName(), getConsumerBrokerUrl());
    MessageConsumer consumer2 = new MessageConsumerBuilder(consumer2Session, testTopic).waitTillStarted().build();
    // When
    producer.send(expectedTextMessage);
    Message message1 = consumer1.receive(1000L);
    Message message2 = consumer2.receive(1000L);
    Assert.assertEquals(testMessage, ((TextMessage) message1).getText());
    Assert.assertEquals(testMessage, ((TextMessage) message2).getText());
    // Wait till all traces are recorded (consumer traces are recorded from another thread)
    awaitAndVerifyTraceCount(9, 5000L);
    // trace count : 1
    verifyProducerSendEvent(testTopic);
    // trace count : 4
    verifyConsumerPullEvent(testTopic, consumer1, expectedTextMessage);
    // trace count : 4
    verifyConsumerPullEvent(testTopic, consumer2, expectedTextMessage);
}
Also used : MessageProducerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageProducerBuilder) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQSession(org.apache.activemq.ActiveMQSession) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) MessageConsumerBuilder(com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.MessageConsumerBuilder) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Aggregations

MessageProducer (javax.jms.MessageProducer)148 Session (javax.jms.Session)106 TextMessage (javax.jms.TextMessage)61 Message (javax.jms.Message)53 Test (org.junit.Test)47 Connection (javax.jms.Connection)46 MessageConsumer (javax.jms.MessageConsumer)40 Topic (javax.jms.Topic)31 JMSException (javax.jms.JMSException)29 Destination (javax.jms.Destination)22 Queue (javax.jms.Queue)21 ConnectionFactory (javax.jms.ConnectionFactory)12 ModelNode (org.jboss.dmr.ModelNode)10 ObjectMessage (javax.jms.ObjectMessage)9 QueueSession (javax.jms.QueueSession)9 TemporaryQueue (javax.jms.TemporaryQueue)8 QueueConnection (javax.jms.QueueConnection)7 InitialContext (javax.naming.InitialContext)7 HornetQMixIn (org.switchyard.component.test.mixins.hornetq.HornetQMixIn)7 Serializable (java.io.Serializable)5