Refine search
/** Sends a request and waits for a reply. The temporary topic is used for * the {@code JMSReplyTo} destination; the first reply is returned, * and any following replies are discarded. * * @param message the message to send * * @return the reply message * * @exception JMSException if the JMS provider fails to complete the * request due to some internal error. */ public Message request(Message message) throws JMSException { message.setJMSReplyTo(tempTopic); publisher.publish(message); return(subscriber.receive()); }
@Override public Topic getTopic() throws JMSException { checkTopicPublisher(); return ((TopicPublisher) delegate).getTopic(); }
/** * 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); }
publisherConnection.stop(); publisherSession = publisherConnection.createTopicSession(true, 0); Assert.assertEquals(true, publisherSession.getTransacted()); publisher = publisherSession.createPublisher(publisherTopic); publisherConnection.start(); subscriberConnection.stop(); subscriberSession = subscriberConnection.createTopicSession(true, 0); Assert.assertEquals(true, subscriberSession.getTransacted()); subscriber = subscriberSession.createSubscriber(subscriberTopic); message.setText("testRollbackReceivedMessage"); publisher.publish(message); publisherSession.commit(); Message msg1 = subscriber.receive(TestConfig.TIMEOUT); Assert.assertTrue("no message received", msg1 != null); Assert.assertTrue(msg1 instanceof TextMessage); Message msg2 = subscriber.receive(TestConfig.TIMEOUT); Assert.assertTrue("no message received after rollbacking subscriber session.", msg2 != null); Assert.assertTrue(msg2 instanceof TextMessage);
publishingSession = jmsConnection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); topicPublisher = publishingSession.createPublisher(topic); message = publishingSession.createBytesMessage(); ((BytesMessage)message).writeBytes((byte[])command); } else { message = publishingSession.createObjectMessage(); ((ObjectMessage)message).setObject((Serializable)command); topicPublisher.publish(message); logDebugAfterPublish(debugInfo, message.getJMSMessageID()); jmsConnection.close();
try { topicConnection = getTopicConnection(); topicConnection.start(); topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = topicSession.createTopic(topicName); topicPublisher = topicSession.createPublisher(topic); TextMessage textMessage = topicSession.createTextMessage(new Gson().toJson(gatewayEvent)); topicPublisher.publish(textMessage); } catch (JMSException e) { String errorMessage = "Error occurred while publishing " + gatewayEvent.getEventType() + " event to JMS " + topicPublisher.close(); } catch (JMSException e) { log.error("Error occurred while closing topic publisher for topic : " + topicName); topicConnection.close(); } catch (JMSException e) { log.error("Error occurred while closing topic connection for topic : " + topicName);
public void testJMSPropMissingWithSomeRequired() throws Exception { JMSAdaptor adaptor = new JMSAdaptor(); adaptor.parseArgs(DATA_TYPE, "vm://localhost -t test.topic " + "-x org.apache.hadoop.chukwa.datacollection.adaptor.jms.JMSMessagePropertyTransformer " + "-p \"foo,bar,num -r foo\"", AdaptorManager.NULL); adaptor.start("id", DATA_TYPE, 0, this); Message message = session.createTextMessage(MESSAGE_PAYLOAD); message.setStringProperty("bar", "bar_value"); message.setStringProperty("bat", "bat_value"); message.setIntProperty("num", 1); publisher.publish(message); synchronized(this) { wait(1000); } assertEquals("Message should not have been received", 0, chunkPayloads.size()); }
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;
/** * 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); } }
@Test(timeout = 60000) public void testSendAndReceiveOnTopic() throws Exception { Connection connection = createConnection("myClientId"); try { TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(getTopicName()); TopicSubscriber consumer = session.createSubscriber(topic); TopicPublisher producer = session.createPublisher(topic); TextMessage message = session.createTextMessage("test-message"); producer.send(message); producer.close(); connection.start(); message = (TextMessage) consumer.receive(1000); assertNotNull(message); assertNotNull(message.getText()); assertEquals("test-message", message.getText()); } finally { connection.close(); } }
topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = topicSession.createTopic(topicName); topic = topicSession.createTopic("BURL:" + topicName); TopicPublisher topicPublisher = topicSession.createPublisher(topic); topicPublisher.setDeliveryMode(deliveryMode); TextMessage textMessage = topicSession.createTextMessage(message.getMessage().toString()); topicPublisher.publish(textMessage); topicPublisher.close(); topicSession.close(); topicConnection.stop(); topicConnection.close(); } catch (JMSException e) { throw new EventBrokerException("Can not publish to topic " + topicName + " " + e.getMessage(), e);
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) {
public Message request(Message message) throws JMSException { TemporaryTopic tempTopic = _session.createTemporaryTopic(); try { message.setJMSReplyTo(tempTopic); _sender.publish(message); TopicSubscriber receiver = _session.createSubscriber(tempTopic); try { return receiver.receive(); } finally { receiver.close(); } } finally { tempTopic.delete(); } }
TopicSession s = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); TopicPublisher publisher = s.createPublisher(ActiveMQServerTestCase.topic1); TopicSubscriber sub = s.createSubscriber(ActiveMQServerTestCase.topic1); conn.start(); to1.text = "hello3"; ObjectMessage om1 = s.createObjectMessage(); om1.setObject(to1); publisher.send(om1); publisher.send(om2); publisher.send(om3); ObjectMessage rm1 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); ObjectMessage rm2 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); ObjectMessage rm3 = (ObjectMessage) sub.receive(ActiveMQServerTestCase.MAX_TIMEOUT); } finally { if (conn != null) { conn.close();
TopicSession session = connection.createTopicSession(IS_TRANSACTED, ACKNOWLEDGE_MODE); TopicPublisher pub = session.createPublisher(topic); pub.setDeliveryMode(DeliveryMode.NON_PERSISTENT); pub.setPriority(Message.DEFAULT_PRIORITY); pub.setTimeToLive(Message.DEFAULT_TIME_TO_LIVE); connection.start(); ); pub.publish(msg); session.commit(); connection.close();
/** * Topics shouldn't hold on to messages if there are no subscribers */ @Test public void testPersistentMessagesForTopicDropped() throws Exception { TopicConnection topicConn = createTopicConnection(); TopicSession sess = topicConn.createTopicSession(true, 0); TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1); pub.setDeliveryMode(DeliveryMode.PERSISTENT); Message m = sess.createTextMessage("testing123"); pub.publish(m); sess.commit(); topicConn.close(); checkEmpty(ActiveMQServerTestCase.topic1); }
protected void stopService () { log.info ("Stoping JMS cache invalidation bridge"); try { if (this.propagationMode == JMSCacheInvalidationBridgeMBean.IN_OUT_BRIDGE_PROPAGATION || this.propagationMode == JMSCacheInvalidationBridgeMBean.IN_ONLY_BRIDGE_PROPAGATION) { subscriber.close(); } if (this.propagationMode == JMSCacheInvalidationBridgeMBean.IN_OUT_BRIDGE_PROPAGATION || this.propagationMode == JMSCacheInvalidationBridgeMBean.OUT_ONLY_BRIDGE_PROPAGATION) { this.publishingAuthorized = false; pub.close(); } conn.stop(); session.close(); conn.close(); } catch (Exception ex) { log.warn("Failed to stop JMS resources associated with the JMS bridge: ", ex); } }
tSession = tConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); Topic topic = getTopic(topicName); tPublisher = tSession.createPublisher(topic); TextMessage message = tSession.createTextMessage(); tConnection.start(); tPublisher.publish(message, DeliveryMode.PERSISTENT, TextMessage.DEFAULT_DELIVERY_MODE, TextMessage.DEFAULT_TIME_TO_LIVE);
sess = conn.createTopicSession(useTransaction, ackMode); publisher = sess.createPublisher(topic); publisher.publish(msg); } catch (final Exception e) { throw new JobExecutionException(e);
/** * Send the JMS Message using matching Message Sender implementation. * * @param destination JMS Queue/Topic. * @param message JMS Message. * @param producer JMS Message Producer. * @throws JMSException Thrown when sending the message. */ private void sendJMSMessage(Destination destination, Message message, MessageProducer producer) throws JMSException { if (JMSConstants.JMSDestinationType.QUEUE.equals(jmsConnectionFactory.getDestinationType()) || !JMSConstants.JMS_SPEC_VERSION_1_0.equals(jmsConnectionFactory.getJmsSpec())) { producer.send(destination, message, message.getJMSDeliveryMode(), message.getJMSPriority(), message.getJMSExpiration()); } else { ((TopicPublisher) producer) .send(destination, message, message.getJMSDeliveryMode(), message.getJMSPriority(), message.getJMSExpiration()); } }