@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"); connection.start(); // for consumer we need to start connection 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); } }
@Test public void testSendMessage() throws Exception { ConnectionFactory connFactory = lookup("ConnectionFactory", ConnectionFactory.class); Connection conn = connFactory.createConnection(); conn.start(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); TemporaryQueue replyQueue = session.createTemporaryQueue(); TextMessage msg = session.createTextMessage("Hello world"); msg.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT); msg.setJMSReplyTo(replyQueue); Queue queue = lookup("java:jboss/" + queueName, Queue.class); MessageProducer producer = session.createProducer(queue); producer.send(msg); MessageConsumer consumer = session.createConsumer(replyQueue); Message replyMsg = consumer.receive(5000); Assert.assertNotNull(replyMsg); if (replyMsg instanceof ObjectMessage) { Exception e = (Exception) ((ObjectMessage) replyMsg).getObject(); throw e; } Assert.assertTrue(replyMsg instanceof TextMessage); String actual = ((TextMessage) replyMsg).getText(); Assert.assertEquals("SUCCESS", actual); consumer.close(); producer.close(); session.close(); conn.stop(); }
public void txtSender(String content, String correlationid) throws JMSException { TextMessage txtMessage = session.createTextMessage(); txtMessage.setText(content); txtMessage.setJMSReplyTo(consumerQueue); String correlationId = correlationid; txtMessage.setJMSCorrelationID(correlationId); System.out.println(correlationId); this.producer.send(txtMessage); }
protected void sendAsynchronousMessage(String messageText) throws JMSException { MessageProducer messageProducer = session.createProducer(counterTopic); TextMessage textMessage = session.createTextMessage(messageText); if (replyTopic == null) { replyTopic = session.createTemporaryTopic(); consumer = session.createConsumer(replyTopic); } textMessage.setJMSReplyTo(replyTopic); messageProducer.send(textMessage); System.out.println("=============================REQUEST========================="); System.out.println(messageText); messageProducer.close(); }
@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (testInfo()) { System.out.println("Log in successful, Welcome!"); Client client = new Client(userName.getText(), passWord.getText()); try { TextMessage textmessage = client.getSession().createTextMessage(); textmessage.setText(" "); textmessage.setJMSCorrelationID(userName.getText()); textmessage.setJMSReplyTo(client.getSession().createQueue(userName.getText())); System.out.println(userName.getText()); client.getProducer().send(Chatwindow.server.getServerTopic(), textmessage); } catch (JMSException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
public static void topicPublish( TopicConnection cnn, String topicName, String payload, boolean transacted, int ack, String replyTo) throws JMSException { TopicSession session = cnn.createTopicSession(transacted, ack); Topic topic = session.createTopic(topicName); TopicPublisher publisher = session.createPublisher(topic); TextMessage msg = session.createTextMessage(); msg.setText(payload); msg.setJMSDeliveryMode(ack); if (replyTo != null) { msg.setJMSReplyTo(session.createTopic(replyTo)); } publisher.publish(msg); publisher.close(); session.close(); }
public static void queueSend( QueueConnection cnn, String queueName, String payload, boolean transacted, int ack, String replyTo) throws JMSException { QueueSession session = cnn.createQueueSession(transacted, ack); Queue queue = session.createQueue(queueName); QueueSender sender = session.createSender(queue); TextMessage msg = session.createTextMessage(); msg.setText(payload); msg.setJMSDeliveryMode(ack); if (replyTo != null) { msg.setJMSReplyTo(session.createQueue(replyTo)); } sender.send(msg); sender.close(); session.close(); }