Search in sources :

Example 1 with ConnectionFactory

use of javax.jms.ConnectionFactory in project hive by apache.

the class TestMsgBusConnection method connectClient.

private void connectClient() throws JMSException {
    ConnectionFactory connFac = new ActiveMQConnectionFactory("tcp://localhost:61616");
    Connection conn = connFac.createConnection();
    conn.start();
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    Destination hcatTopic = session.createTopic("planetlab.hcat");
    consumer = session.createConsumer(hcatTopic);
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Destination(javax.jms.Destination) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 2 with ConnectionFactory

use of javax.jms.ConnectionFactory in project storm by apache.

the class JmsSpout method open.

/**
     * <code>ISpout</code> implementation.
     * <p>
     * Connects the JMS spout to the configured JMS destination
     * topic/queue.
     */
@SuppressWarnings("rawtypes")
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    if (this.jmsProvider == null) {
        throw new IllegalStateException("JMS provider has not been set.");
    }
    if (this.tupleProducer == null) {
        throw new IllegalStateException("JMS Tuple Producer has not been set.");
    }
    Integer topologyTimeout = (Integer) conf.get("topology.message.timeout.secs");
    // TODO fine a way to get the default timeout from storm, so we're not hard-coding to 30 seconds (it could change)
    topologyTimeout = topologyTimeout == null ? 30 : topologyTimeout;
    if ((topologyTimeout.intValue() * 1000) > this.recoveryPeriod) {
        LOG.warn("*** WARNING *** : " + "Recovery period (" + this.recoveryPeriod + " ms.) is less then the configured " + "'topology.message.timeout.secs' of " + topologyTimeout + " secs. This could lead to a message replay flood!");
    }
    this.queue = new LinkedBlockingQueue<Message>();
    this.toCommit = new TreeSet<JmsMessageID>();
    this.pendingMessages = new HashMap<JmsMessageID, Message>();
    this.collector = collector;
    try {
        ConnectionFactory cf = this.jmsProvider.connectionFactory();
        Destination dest = this.jmsProvider.destination();
        this.connection = cf.createConnection();
        this.session = connection.createSession(false, this.jmsAcknowledgeMode);
        MessageConsumer consumer = session.createConsumer(dest);
        consumer.setMessageListener(this);
        this.connection.start();
        if (this.isDurableSubscription() && this.recoveryPeriod > 0) {
            this.recoveryTimer = new Timer();
            this.recoveryTimer.scheduleAtFixedRate(new RecoveryTask(), 10, this.recoveryPeriod);
        }
    } catch (Exception e) {
        LOG.warn("Error creating JMS connection.", e);
    }
}
Also used : Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) JMSException(javax.jms.JMSException) ConnectionFactory(javax.jms.ConnectionFactory)

Example 3 with ConnectionFactory

use of javax.jms.ConnectionFactory in project karaf by apache.

the class JmsConnector method connect.

public Connection connect() throws JMSException {
    reference = this.lookupConnectionFactory(connectionFactoryName);
    ConnectionFactory cf = bc.getService(reference);
    connection = cf.createConnection(username, password);
    connection.start();
    return connection;
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory)

Example 4 with ConnectionFactory

use of javax.jms.ConnectionFactory in project wildfly by wildfly.

the class HelloBean method sendMessage.

public String sendMessage() throws Exception {
    String destinationName = "java:jboss/exported/queue/TestQueue";
    Context ic = null;
    ConnectionFactory cf = null;
    Connection connection = null;
    try {
        ic = getInitialContext();
        cf = (ConnectionFactory) ic.lookup("java:/ConnectionFactory");
        Queue queue = (Queue) ic.lookup(destinationName);
        connection = cf.createConnection("guest", "guest");
        // we need to start connection for consumer
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer sender = session.createProducer(queue);
        TextMessage message = session.createTextMessage("hello goodbye");
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        message.setJMSReplyTo(replyQueue);
        sender.send(message);
        MessageConsumer consumer = session.createConsumer(replyQueue);
        TextMessage replyMsg = (TextMessage) consumer.receive(5000);
        log.trace("Message received:" + replyMsg);
        return replyMsg.getText();
    } finally {
        if (ic != null) {
            try {
                ic.close();
            } catch (Exception ignore) {
            }
        }
        closeConnection(connection);
    }
}
Also used : InitialContext(javax.naming.InitialContext) SessionContext(javax.ejb.SessionContext) Context(javax.naming.Context) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) Session(javax.jms.Session)

Example 5 with ConnectionFactory

use of javax.jms.ConnectionFactory in project wildfly by wildfly.

the class RunAsTestCaseEJBMDB method testSendMessage.

@Test
public void testSendMessage() throws Exception {
    ConnectionFactory cf = null;
    Connection connection = null;
    Session session = null;
    try {
        cf = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
        Queue queue = (Queue) initialContext.lookup(QUEUE_NAME);
        connection = cf.createConnection("guest", "guest");
        //for consumer we need to start connection
        connection.start();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer sender = session.createProducer(queue);
        TemporaryQueue replyQueue = session.createTemporaryQueue();
        TextMessage message = session.createTextMessage("hello goodbye");
        message.setJMSReplyTo(replyQueue);
        sender.send(message);
        log.trace("testSendMessage(): Message sent!");
        MessageConsumer consumer = session.createConsumer(replyQueue);
        Message replyMsg = consumer.receive(5000);
        Assert.assertNotNull(replyMsg);
        Assert.assertTrue(replyMsg instanceof TextMessage);
        String actual = ((TextMessage) replyMsg).getText();
        Assert.assertEquals("Howdy Fred! GoodBye user1", actual);
    } finally {
        if (session != null) {
            session.close();
        }
        closeConnection(connection);
    }
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) TemporaryQueue(javax.jms.TemporaryQueue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ConnectionFactory (javax.jms.ConnectionFactory)660 Connection (javax.jms.Connection)246 CamelContext (org.apache.camel.CamelContext)220 Session (javax.jms.Session)203 TextMessage (javax.jms.TextMessage)158 MessageProducer (javax.jms.MessageProducer)148 MessageConsumer (javax.jms.MessageConsumer)146 Test (org.junit.Test)142 InitialContext (javax.naming.InitialContext)120 JMSException (javax.jms.JMSException)113 Destination (javax.jms.Destination)102 Queue (javax.jms.Queue)102 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)83 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)64 Message (javax.jms.Message)62 Context (javax.naming.Context)37 NamingException (javax.naming.NamingException)37 JMSContext (javax.jms.JMSContext)35 QueueConnectionFactory (javax.jms.QueueConnectionFactory)35 TopicConnectionFactory (javax.jms.TopicConnectionFactory)35