public JMSSink( String tcfBindingName, String topicBindingName, String username, String password) { try { Context ctx = new InitialContext(); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password); topicConnection.start(); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic)ctx.lookup(topicBindingName); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); } catch(JMSException e) { logger.error("Could not read JMS message.", e); } catch(NamingException e) { logger.error("Could not read JMS message.", e); } catch(RuntimeException e) { logger.error("Could not read JMS message.", e); } }
if (outboundUsername != null) { newConnection = outboundTopicConnectionFactory .createTopicConnection(outboundUsername, outboundPassword); } else { newConnection = outboundTopicConnectionFactory.createTopicConnection(); if (outboundUsername != null) { newConnection = outboundTopicConnectionFactory .createTopicConnection(outboundUsername, outboundPassword); } else { newConnection = outboundTopicConnectionFactory.createTopicConnection(); newConnection.setExceptionListener(new ExceptionListener() { @Override public void onException(JMSException exception) { newConnection.setClientID(getOutboundClientId()); newConnection.start(); if (newConnection != null) { try { newConnection.close(); } catch (Exception ignore) {}
TopicSession nonTxSession = mock(TopicSession.class); given(cf.createTopicConnection()).willReturn(con); given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession); given(txSession.getTransacted()).willReturn(true); given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession); con1.start(); TopicConnection con2 = scf.createTopicConnection(); Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE); session2.close(); session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE); session2.getTransacted(); session2.close(); con2.start(); con1.close(); con2.close(); verify(txSession).close(); verify(nonTxSession).close(); verify(con).start(); verify(con).stop(); verify(con).close();
jndi = new InitialContext(env); } else { jndi = new InitialContext(); LogLog.debug("About to create TopicConnection."); if(userName != null) { topicConnection = topicConnectionFactory.createTopicConnection(userName, password); } else { topicConnection = topicConnectionFactory.createTopicConnection(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topicPublisher = topicSession.createPublisher(topic); topicConnection.start(); jndi.close(); } catch(JMSException e) { errorHandler.error("Error while activating options for appender named ["+name+
public JMSSink( String tcfBindingName, String topicBindingName, String username, String password) { try { Context ctx = new InitialContext(); TopicConnectionFactory topicConnectionFactory; topicConnectionFactory = (TopicConnectionFactory) lookup(ctx, tcfBindingName); TopicConnection topicConnection = topicConnectionFactory.createTopicConnection(username, password); topicConnection.start(); TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic)ctx.lookup(topicBindingName); TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic); topicSubscriber.setMessageListener(this); } catch(Exception e) { logger.error("Could not read JMS message.", e); } }
protected void connect() { try { Context ctx = newContext(); TopicConnectionFactory tcf = (TopicConnectionFactory) ctx.lookup(_tcfName); Topic topic = (Topic) ctx.lookup(_topicName); ctx.close(); _connection = tcf.createTopicConnection(); // false == not transacted. _session = _connection.createTopicSession (false, Session.AUTO_ACKNOWLEDGE); // create a publisher _publisher = _session.createPublisher(topic); // create a subscriber. TopicSubscriber s = _session.createSubscriber(topic, null, /* noLocal: */ true); MessageListener l = getMessageListener(); s.setMessageListener(l); _connection.start(); _connection.setExceptionListener(this); if (log.isInfoEnabled()) log.info(s_loc.get("jms-start-listener", _topicName)); } catch (OpenJPAException ke) { throw ke; } catch (Exception e) { throw new UserException(s_loc.get("jms-provider-config", _topicName, _tcfName), e).setFatal(true); } }
env.put(Context.PROVIDER_URL, providerUrl); connectionFactory = (javax.jms.TopicConnectionFactory)ctx.lookup(cfName); "Topic connection factory cannot be found in JNDI."); topic = (javax.jms.Topic)ctx.lookup(topicName); connection = connectionFactory.createTopicConnection(); connection.setClientID(generateLocalAddress()); addressAssigned = true; } catch (javax.jms.IllegalStateException e) { local_addr = new JMSAddress(connection.getClientID(), false); mcast_addr = new JMSAddress(topicName, true); session = connection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); publisher = session.createPublisher(topic); publisher.setTimeToLive(timeToLive); subscriber = session.createSubscriber(topic); subscriber.setMessageListener(this); connection.start();
ppt2.put(Context.PROVIDER_URL, "tcp://localhost:61616"); ppt2.put("topic.MessageDestinationTopic", "console.jms/TopicQueue/JCAAdminObject/MessageDestinationTopic"); Context ctx2 = new InitialContext(ppt2); TopicConnectionFactory factory = (TopicConnectionFactory) ctx2.lookup("ConnectionFactory"); TopicConnection connection = factory.createTopicConnection(); TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic) ctx2.lookup("MessageDestinationTopic"); MessageProducer producer = session.createProducer(topic); TextMessage msg = session.createTextMessage(); msg.setText("this is a test message"); producer.send(msg); producer.close(); session.close(); System.out.println("Message published. Please check application server's console to see the response from MDB"); ctx2.close(); System.exit(0);
Context ctx = new InitialContext(); // lookup the topic connection factory TopicConnectionFactory connFactory = (TopicConnectionFactory) ctx .lookup("/RemoteConnectionFactory"); // lookup the topic object Topic topic = (Topic) ctx.lookup("java:/"+prop.TOPIC); // create a topic connection TopicConnection topicConn = connFactory.createTopicConnection(prop.USERPUB,prop.PASSPUB); //create topic session TopicSession topicSession = topicConn.createTopicSession(true, Session.AUTO_ACKNOWLEDGE); //create topic publisher MessageProducer topicPublisher = topicSession.createPublisher(topic); topicPublisher.setDeliveryMode(DeliveryMode.PERSISTENT);
public void run(String dest) throws Exception { InitialContext ic = getInitialContext(); TopicConnectionFactory confac = (TopicConnectionFactory) ic.lookup("ConnectionFactory"); TopicConnection connection = confac.createTopicConnection(); TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(dest); TopicSubscriber topicSubscriber = session.createSubscriber(topic); topicSubscriber.setMessageListener(this); System.out.println("MDD-Consumer listening for topic : "+topic.getTopicName()); connection.start(); } public void onMessage(Message message){
factory = (TopicConnectionFactory) jndi.lookup(jndiName); } catch (GeneralException ge) { throw new GenericServiceException("Problems getting JNDI InitialContext.", ge.getNested()); try { jndi = JNDIContextFactory.getInitialContext(serverName); factory = (TopicConnectionFactory) jndi.lookup(jndiName); } catch (GeneralException ge2) { throw new GenericServiceException("Problems getting JNDI InitialContext.", ge2.getNested()); con = factory.createTopicConnection(userName, password); con.setClientID(clientId); con.start(); TopicSession session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = (Topic) jndi.lookup(topicName); TopicPublisher publisher = session.createPublisher(topic); publisher.publish(message); if (Debug.verboseOn()) Debug.logVerbose("Sent JMS Message to " + topicName, module); publisher.close(); session.close(); con.close(); } catch (NamingException ne) { throw new GenericServiceException("Problems with JNDI lookup.", ne);
publisherTCF = (TopicConnectionFactory) ctx.lookup(TCF_NAME); publisherTopic = (Topic) ctx.lookup(TOPIC_NAME); publisherConnection = publisherTCF.createTopicConnection(); publisherConnection.setClientID("publisherConnection"); publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); publisher = publisherSession.createPublisher(publisherTopic); subscriberTCF = (TopicConnectionFactory) ctx.lookup(TCF_NAME); subscriberTopic = (Topic) ctx.lookup(TOPIC_NAME); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createSubscriber(subscriberTopic); publisherConnection.start(); subscriberConnection.start();
.lookup(dataMap .getString(JmsHelper.JMS_CONNECTION_FACTORY_JNDI)); conn = connFactory.createTopicConnection(); } else { final String user = dataMap.getString(JmsHelper.JMS_USER); .getString(JmsHelper.JMS_PASSWORD); conn = connFactory.createTopicConnection(user, password); sess = conn.createTopicSession(useTransaction, ackMode); final Topic topic = (Topic) namingCtx.lookup(dataMap .getString(JmsHelper.JMS_DESTINATION_JNDI)); publisher = sess.createPublisher(topic); publisher.publish(msg); } catch (final Exception e) { throw new JobExecutionException(e);
publisherTCF = (TopicConnectionFactory) ctx.lookup(PubSubTestCase.TCF_NAME); publisherTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME); publisherConnection = publisherTCF.createTopicConnection(); publisherConnection.setClientID("publisherConnection"); publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); publisher = publisherSession.createPublisher(publisherTopic); subscriberTCF = (TopicConnectionFactory) ctx.lookup(PubSubTestCase.TCF_NAME); subscriberTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createSubscriber(subscriberTopic); publisherConnection.start(); subscriberConnection.start();
public synchronized void load() throws GenericServiceException { try { InitialContext jndi = JNDIContextFactory.getInitialContext(jndiServer); TopicConnectionFactory factory = (TopicConnectionFactory) jndi.lookup(jndiName); con = factory.createTopicConnection(userName, password); con.setExceptionListener(this); session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) jndi.lookup(topicName); if (topic != null) { TopicSubscriber subscriber = session.createSubscriber(topic); subscriber.setMessageListener(this); con.start(); this.setConnected(true); if (Debug.infoOn()) Debug.logInfo("Listening to topic [" + topicName + "] on [" + jndiServer + "]...", module);
.lookup(JmsHelper.JMS_CONNECTION_FACTORY_JNDI); connection = tcf.createTopicConnection(user, pw); connection = tcf.createTopicConnection(); session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) ctx.lookup(JmsHelper.JMS_DESTINATION_JNDI); publisher = session.createPublisher(topic); String factoryClassName = jobDataMap.getString(JmsHelper.JMS_MSG_FACTORY_CLASS_NAME); JmsMessageFactory factory = JmsHelper.getMessageFactory(factoryClassName); Message m = factory.createMessage(jobDataMap, session); publisher.publish(m);
/** * Test that ConnectionFactory can be cast to TopicConnectionFactory and TopicConnection can be * created. */ @Test public void testTopicConnectionFactory() throws Exception { deployConnectionFactory(0, JMSFactoryType.TOPIC_CF, "CF_TOPIC_XA_FALSE", "/CF_TOPIC_XA_FALSE"); TopicConnectionFactory qcf = (TopicConnectionFactory) ic.lookup("/CF_TOPIC_XA_FALSE"); TopicConnection tc = qcf.createTopicConnection(); tc.close(); undeployConnectionFactory("CF_TOPIC_XA_FALSE"); }
/** * Topics shouldn't hold on to messages when the non-durable subscribers close */ @Test public void testPersistentMessagesForTopicDropped2() throws Exception { TopicConnection topicConn = createTopicConnection(); topicConn.start(); TopicSession sess = topicConn.createTopicSession(true, 0); TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1); TopicSubscriber sub = sess.createSubscriber(ActiveMQServerTestCase.topic1); pub.setDeliveryMode(DeliveryMode.PERSISTENT); Message m = sess.createTextMessage("testing123"); pub.publish(m); sess.commit(); // receive but rollback TextMessage m2 = (TextMessage) sub.receive(3000); ProxyAssertSupport.assertNotNull(m2); ProxyAssertSupport.assertEquals("testing123", m2.getText()); sess.rollback(); topicConn.close(); checkEmpty(ActiveMQServerTestCase.topic1); }
/** * Test that a durable subscriber effectively receives the messages sent to * its topic while it was inactive. */ public void testDurableSubscriber() { try { subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.close(); subscriberConnection = null; TextMessage message = publisherSession.createTextMessage(); message.setText("test"); publisher.publish(message); subscriberConnection = subscriberTCF.createTopicConnection(); subscriberConnection.setClientID("subscriberConnection"); subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); subscriber = subscriberSession.createDurableSubscriber(subscriberTopic, "testTopic"); subscriberConnection.start(); TextMessage m = (TextMessage) subscriber.receive(TestConfig.TIMEOUT); Assert.assertTrue(m != null); Assert.assertEquals("test", m.getText()); } catch (JMSException e) { fail(e); } }
publisherConnection.stop(); subscriberConnection.stop(); tempTopic = subscriberSession.createTemporaryTopic(); publisher = publisherSession.createPublisher(tempTopic); tempSubscriber = subscriberSession.createSubscriber(tempTopic); subscriberConnection.start(); publisherConnection.start(); TextMessage message = publisherSession.createTextMessage(); message.setText("testTemporaryTopic"); publisher.publish(message); Message m = tempSubscriber.receive(TestConfig.TIMEOUT); assertTrue(m instanceof TextMessage); TextMessage msg = (TextMessage) m;