congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
TextMessage
Code IndexAdd Tabnine to your IDE (free)

How to use
TextMessage
in
javax.jms

Best Java code snippets using javax.jms.TextMessage (Showing top 20 results out of 2,286)

Refine searchRefine arrow

  • MessageProducer
  • Session
  • MessageConsumer
  • Connection
  • ActiveMQConnection
  • ConnectionFactory
origin: apache/activemq

public void testCloseConsumer() throws Exception {
  Destination dest = session.createQueue(getSubject() + "?consumer.prefetchSize=0");
  producer = session.createProducer(dest);
  beginTx();
  producer.send(session.createTextMessage("message 1"));
  producer.send(session.createTextMessage("message 2"));
  commitTx();
  beginTx();
  consumer = session.createConsumer(dest);
  Message message1 = consumer.receive(1000);
  String text1 = ((TextMessage)message1).getText();
  assertNotNull(message1);
  assertEquals("message 1", text1);
  consumer.close();
  consumer = session.createConsumer(dest);
  Message message2 = consumer.receive(1000);
  String text2 = ((TextMessage)message2).getText();
  assertNotNull(message2);
  assertEquals("message 2", text2);
  commitTx();
}
origin: kiegroup/jbpm

MessageProducer producer = null;
try {
  queueConnection = connectionFactory.createConnection();
  queueSession = queueConnection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
  TextMessage message = queueSession.createTextMessage(eventXml);
  message.setIntProperty("EventType", eventType);
  message.setStringProperty("LogType", "Process");
  producer = queueSession.createProducer(queue);  
  producer.setPriority(priority);
  producer.send(message);
} catch (Exception e) {
  throw new RuntimeException("Error when sending JMS message with working memory event", e);
  if (producer != null) {
    try {
      producer.close();
    } catch (JMSException e) {
      logger.warn("Error when closing producer", e);
      queueSession.close();
    } catch (JMSException e) {
      logger.warn("Error when closing queue session", e);
      queueConnection.close();
    } catch (JMSException e) {
      logger.warn("Error when closing queue connection", e);
origin: spring-projects/spring-framework

@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
  Queue destination = mock(Queue.class);
  TextMessage sentTextMessage = mock(TextMessage.class);
  // correlation ID is queried when response is being created...
  given(sentTextMessage.getJMSCorrelationID()).willReturn(null);
  given(sentTextMessage.getJMSMessageID()).willReturn(CORRELATION_ID);
  // Reply-To is queried when response is being created...
  given(sentTextMessage.getJMSReplyTo()).willReturn(destination);
  TextMessage responseTextMessage = mock(TextMessage.class);
  MessageProducer messageProducer = mock(MessageProducer.class);
  Session session = mock(Session.class);
  given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
  given(session.createProducer(destination)).willReturn(messageProducer);
  ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
  given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
  MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
    @Override
    protected Object extractMessage(Message message) {
      return message;
    }
  };
  adapter.onMessage(sentTextMessage, session);
  verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
  verify(messageProducer).send(responseTextMessage);
  verify(messageProducer).close();
  verify(delegate).handleMessage(sentTextMessage);
}
origin: spring-projects/spring-framework

private void assertTextMessage(MessageCreator messageCreator) {
  try {
    TextMessage jmsMessage = createTextMessage(messageCreator);
    assertEquals("Wrong body message", "Hello", jmsMessage.getText());
    assertEquals("Invalid foo property", "bar", jmsMessage.getStringProperty("foo"));
  }
  catch (JMSException e) {
    throw new IllegalStateException("Wrong text message", e);
  }
}
origin: apache/activemq-artemis

@Test
public void testTopic2() throws Exception {
 Connection conn = createConnection();
 Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
 MessageProducer p = s.createProducer(ActiveMQServerTestCase.topic1);
 MessageConsumer c = s.createConsumer(ActiveMQServerTestCase.topic1);
 conn.start();
 p.send(s.createTextMessage("payload"));
 TextMessage m = (TextMessage) c.receive();
 ProxyAssertSupport.assertEquals("payload", m.getText());
}
origin: mercyblitz/segmentfault-lessons

private static void receiveMessage() throws Exception {
  // 创建 ActiveMQ 链接,设置 Broker URL
  ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
  // 创造 JMS 链接
  Connection connection = connectionFactory.createConnection();
  // 启动连接
  connection.start();
  // 创建会话 Session
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  // 创建消息目的 - Queue 名称为 "TEST"
  Destination destination = session.createQueue("TEST");
  // 创建消息消费者
  MessageConsumer messageConsumer = session.createConsumer(destination);
  // 获取消息
  Message message = messageConsumer.receive(100);
  if (message instanceof TextMessage) {
    TextMessage textMessage = (TextMessage) message;
    System.out.println("消息消费内容:" + textMessage.getText());
  }
  // 关闭消息消费者
  messageConsumer.close();
  // 关闭会话
  session.close();
  // 关闭连接
  connection.stop();
  connection.close();
}
origin: apache/activemq-artemis

@Test
public void testAutoSend() throws Exception {
 connection.start();
 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 Queue queue = session.createQueue(queueName);
 MessageConsumer consumer = session.createConsumer(queue);
 MessageProducer producer = session.createProducer(queue);
 for (int i = 0; i < 10; i++) {
   producer.send(session.createTextMessage("testXX" + i));
 }
 connection.start();
 for (int i = 0; i < 10; i++) {
   TextMessage txt = (TextMessage) consumer.receive(5000);
   Assert.assertEquals("testXX" + i, txt.getText());
 }
}
origin: apache/activemq-artemis

private void receiveLVQ(ConnectionSupplier consumerConnectionSupplier, String queueName, String lastValueKey) throws JMSException {
 try (Connection consumerConnection = consumerConnectionSupplier.createConnection()) {
   Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue consumerQueue = consumerSession.createQueue(queueName);
   MessageConsumer consumer = consumerSession.createConsumer(consumerQueue);
   TextMessage msg = (TextMessage) consumer.receive(1000);
   assertNotNull(msg);
   assertEquals("KEY", msg.getStringProperty(lastValueKey));
   assertEquals("how are you", msg.getText());
   consumer.close();
 }
}
origin: apache/activemq-artemis

private void sendLVQ(ConnectionSupplier producerConnectionSupplier, String queueName, String lastValueKey) throws JMSException {
 try (Connection connection = producerConnectionSupplier.createConnection();
    Session session = connection.createSession();
    MessageProducer producer = session.createProducer(session.createQueue(queueName))) {
   TextMessage message1 = session.createTextMessage();
   message1.setStringProperty(lastValueKey, "KEY");
   message1.setText("hello");
   producer.send(message1);
   TextMessage message2 = session.createTextMessage();
   message2.setStringProperty(lastValueKey, "KEY");
   message2.setText("how are you");
   producer.send(message2);
 }
}
origin: apache/activemq-artemis

public void sendMessage(SimpleString queue) throws Exception {
 ConnectionFactory fact = getCF();
 Connection connection = fact.createConnection();
 try {
   Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   connection.start();
   Destination destination = session.createQueue(queue.toString());
   MessageProducer producer = session.createProducer(destination);
   TextMessage message = session.createTextMessage();
   message.setText("Message");
   producer.send(message);
 } finally {
   connection.close();
 }
}
origin: spring-projects/spring-framework

given(this.session.createConsumer(this.queue,
    messageSelector ? selectorString : null)).willReturn(messageConsumer);
  given(this.session.getAcknowledgeMode()).willReturn(
      clientAcknowledge ? Session.CLIENT_ACKNOWLEDGE
          : Session.AUTO_ACKNOWLEDGE);
  given(textMessage.getText()).willReturn("Hello World!");
  given(messageConsumer.receiveNoWait()).willReturn(textMessage);
  given(messageConsumer.receive()).willReturn(textMessage);
  given(messageConsumer.receive(timeout)).willReturn(textMessage);
verify(this.connection).start();
verify(this.connection).close();
if (useTransactedTemplate()) {
  verify(this.session).commit();
verify(this.session).close();
if (!useTransactedSession() && clientAcknowledge) {
  verify(textMessage).acknowledge();
verify(messageConsumer).close();
origin: apache/activemq-artemis

@Test(timeout = 60000)
public void testCreateTemporaryTopic() throws Throwable {
 Connection connection = createConnection();
 Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 TemporaryTopic topic = session.createTemporaryTopic();
 System.out.println("topic:" + topic.getTopicName());
 MessageConsumer consumer = session.createConsumer(topic);
 MessageProducer producer = session.createProducer(topic);
 TextMessage message = session.createTextMessage();
 message.setText("Message temporary");
 producer.send(message);
 connection.start();
 message = (TextMessage) consumer.receive(5000);
 assertNotNull(message);
}
origin: apache/activemq-artemis

@Test
public void testRollbackLocal() throws Exception {
 connection.start();
 Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
 Queue queue = session.createQueue(queueName);
 MessageConsumer consumer = session.createConsumer(queue);
 MessageProducer producer = session.createProducer(queue);
 for (int i = 0; i < 10; i++) {
   TextMessage msg = session.createTextMessage("testXX" + i);
   msg.setStringProperty("count", "str " + i);
   producer.send(msg);
 }
 session.commit();
 connection.start();
 for (int i = 0; i < 5; i++) {
   TextMessage txt = (TextMessage) consumer.receive(500);
   Assert.assertEquals("testXX" + i, txt.getText());
 }
 session.rollback();
 for (int i = 0; i < 10; i++) {
   TextMessage txt = (TextMessage) consumer.receive(5000);
   Assert.assertNotNull(txt);
   System.out.println("TXT " + txt.getText());
   Assert.assertEquals("testXX" + i, txt.getText());
 }
 checkDuplicate(consumer);
 session.commit();
}
origin: apache/activemq

/**
 * Sends a batch of messages and validates that the messages are received.
 *
 * @throws Exception
 */
public void testSendReceiveTransactedBatches() throws Exception {
  TextMessage message = session.createTextMessage("Batch Message");
  for (int j = 0; j < batchCount; j++) {
    LOG.info("Producing bacth " + j + " of " + batchSize + " messages");
    beginTx();
    for (int i = 0; i < batchSize; i++) {
      producer.send(message);
    }
    messageSent();
    commitTx();
    LOG.info("Consuming bacth " + j + " of " + batchSize + " messages");
    beginTx();
    for (int i = 0; i < batchSize; i++) {
      message = (TextMessage)consumer.receive(1000 * 5);
      assertNotNull("Received only " + i + " messages in batch " + j, message);
      assertEquals("Batch Message", message.getText());
    }
    commitTx();
  }
}
origin: apache/karaf

@Override
public Object execute() throws Exception {
  Connection connection = connectionFactory.createConnection();
  connection.start();
  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createQueue(queue);
  MessageConsumer consumer = session.createConsumer(destination);
  TextMessage message = (TextMessage) consumer.receive(60000);
  if (message == null) {
    throw new IllegalStateException("No message received");
  } else {
    System.out.println(message.getText());
  }
  return null;
}
origin: apache/activemq-artemis

private void sendTextMessages(int nMsgs, ConnectionFactory factory) throws Exception {
 try (Connection connection = factory.createConnection()) {
   Session session = connection.createSession();
   Queue queue = session.createQueue(testQueueName);
   MessageProducer producer = session.createProducer(queue);
   TextMessage msg = session.createTextMessage();
   StringBuilder builder = new StringBuilder();
   for (int i = 0; i < PAYLOAD; ++i) {
    builder.append("A");
   }
   msg.setText(builder.toString());
   for (int i = 0; i < nMsgs; ++i) {
    msg.setIntProperty("i", (Integer) i);
    producer.send(msg);
   }
 }
}
origin: stackoverflow.com

final ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
   final javax.jms.Connection connection = connectionFactory.createConnection();
   connection.setClientID("12345");
   connection.start();
   final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   final Topic temporaryTopic = session.createTemporaryTopic();
   final MessageConsumer consumer1 = session.createConsumer(temporaryTopic);
   final MessageProducer producer = session.createProducer(temporaryTopic);
   producer.send(session.createTextMessage("Testmessage"));
   final TextMessage message = (TextMessage)consumer1.receiveNoWait();
   Assert.assertNotNull(message);
   Assert.assertEquals("testing", message.getText());
origin: apache/activemq-artemis

@Test
public void testDurableConsumerSelectorChange() throws Exception {
 TextMessage message = session.createTextMessage("1st");
 message.setStringProperty("color", "red");
 producer.send(message);
 Message m = consumer.receive(1000);
 assertNotNull(m);
 assertEquals("1st", ((TextMessage) m).getText());
 consumer.close();
 consumer = session.createDurableSubscriber((Topic) destination, "test", "color='blue'", false);
 message = session.createTextMessage("2nd");
 message.setStringProperty("color", "red");
 producer.send(message);
 message = session.createTextMessage("3rd");
 message.setStringProperty("color", "blue");
 producer.send(message);
 m = consumer.receive(1000);
 assertNotNull(m);
 assertEquals("3rd", ((TextMessage) m).getText());
 assertNull(consumer.receiveNoWait());
origin: spring-projects/spring-integration

  public void onMessage(javax.jms.Message request, Session session) throws JMSException {
    String text = "priority=" + request.getJMSPriority();
    TextMessage reply = session.createTextMessage(text);
    MessageProducer producer = session.createProducer(request.getJMSReplyTo());
    reply.setJMSCorrelationID(request.getJMSMessageID());
    producer.send(reply);
  }
}
origin: io.tracee.examples/tracee-examples-jms-impl

private void sendToDestination(String message, Destination destination) {
  Connection connection = null;
  try {
    connection = connectionFactory.createConnection();
    final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final javax.jms.MessageProducer producer = TraceeMessageWriter.wrap(session.createProducer(destination));
    final TextMessage textMessage = session.createTextMessage();
    textMessage.setText(message);
    LOG.info("I am about to send the message \"{]\" to {}", message, destination.toString());
    producer.send(textMessage);
    session.commit();
  } catch (JMSException jmse) {
    throw new RuntimeException("This example is so cheap, this must not have happened!", jmse);
  }
}
javax.jmsTextMessage

Javadoc

A TextMessage object is used to send a message containing a java.lang.String. It inherits from the Message interface and adds a text message body.

This message type can be used to transport text-based messages, including those with XML content.

When a client receives a TextMessage, it is in read-only mode. If a client attempts to write to the message at this point, a MessageNotWriteableException is thrown. If clearBody is called, the message can now be both read from and written to.

Most used methods

  • getText
    Gets the string containing this message's data. The default value is null.
  • setText
    Sets the string containing this message's data.
  • setStringProperty
  • setJMSCorrelationID
  • setIntProperty
  • setLongProperty
  • getStringProperty
  • setBooleanProperty
  • setJMSReplyTo
  • getJMSCorrelationID
  • getJMSMessageID
  • getJMSReplyTo
  • getJMSMessageID,
  • getJMSReplyTo,
  • setDoubleProperty,
  • acknowledge,
  • setJMSType,
  • getJMSDeliveryMode,
  • setObjectProperty,
  • getIntProperty,
  • getJMSPriority,
  • clearBody

Popular in Java

  • Making http requests using okhttp
  • getContentResolver (Context)
  • setScale (BigDecimal)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • Color (java.awt)
    The Color class is used to encapsulate colors in the default sRGB color space or colors in arbitrary
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • String (java.lang)
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now