Java Code Examples for javax.jms.ObjectMessage#setStringProperty()

The following examples show how to use javax.jms.ObjectMessage#setStringProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedRestActiveMQJMSTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static void publish(String destination, Serializable object, String contentType) throws Exception {
   Connection conn = factory.createConnection();
   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Destination dest = session.createQueue(destination);

   try {
      assertNotNull("Destination was null", dest);
      MessageProducer producer = session.createProducer(dest);
      ObjectMessage message = session.createObjectMessage();

      if (contentType != null) {
         message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
      }
      message.setObject(object);

      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example 2
Source File: JMSTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void publish(String dest, Serializable object, String contentType) throws Exception {
   Connection conn = connectionFactory.createConnection();
   try {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = createDestination(dest);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();

      if (contentType != null) {
         message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
      }
      message.setObject(object);

      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example 3
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void publish(String dest, Serializable object, String contentType, String tag) throws Exception {
   Connection conn = connectionFactory.createConnection();
   try {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Destination destination = createDestination(dest);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();

      if (contentType != null) {
         message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
      }
      if (tag != null) {
         message.setStringProperty("MyTag", tag);
      }
      message.setObject(object);

      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example 4
Source File: EmbeddedTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void publish(String destination, Serializable object, String contentType) throws Exception {
   ConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("vm://0","cf");
   Connection conn = factory.createConnection();
   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Destination dest = session.createQueue(destination);

   try {
      Assert.assertNotNull("Destination was null", dest);
      MessageProducer producer = session.createProducer(dest);
      ObjectMessage message = session.createObjectMessage();

      if (contentType != null) {
         message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
      }
      message.setObject(object);

      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example 5
Source File: RestDeserializationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void jmsSendMessage(Serializable value, String destName, boolean isQueue) throws JMSException {
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   String jmsDest;
   if (isQueue) {
      jmsDest = QUEUE_QUALIFIED_PREFIX + destName;
   } else {
      jmsDest = TOPIC_QUALIFIED_PREFIX + destName;
   }
   Destination destination = ActiveMQDestination.fromPrefixedName(jmsDest);

   Connection conn = factory.createConnection();
   try {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();
      message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, "application/xml");
      message.setObject(value);
      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example 6
Source File: JmsTransactionalStorage.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public String storeMessage(String messageId, String correlationId, Date receivedDate, String comments, String label, S message) throws SenderException {
	Session session=null;
	try {
		session = createSession();
		ObjectMessage msg = session.createObjectMessage(message);
		msg.setStringProperty(FIELD_TYPE,getType());
		msg.setStringProperty(FIELD_ORIGINAL_ID,messageId);
		msg.setJMSCorrelationID(correlationId);
		msg.setLongProperty(FIELD_RECEIVED_DATE,receivedDate.getTime());
		msg.setStringProperty(FIELD_COMMENTS,comments);
		if (StringUtils.isNotEmpty(getSlotId())) {
			msg.setStringProperty(FIELD_SLOTID,getSlotId());
		}
		msg.setStringProperty(FIELD_LABEL,label);
		return send(session,getDestination(),msg);
	} catch (Exception e) {
		throw new SenderException(e);
	} finally {
		closeSession(session);
	}
}
 
Example 7
Source File: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testSendEmptyMessages() throws Exception {
   Queue dest = new ActiveMQQueue(queueName);

   QueueSession defaultQueueSession =  connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   QueueSender defaultSender = defaultQueueSession.createSender(dest);
   defaultSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
   connection.start();

   Message msg = defaultQueueSession.createMessage();
   msg.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(msg);

   QueueReceiver queueReceiver = defaultQueueSession.createReceiver(dest);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //bytes
   BytesMessage bytesMessage = defaultQueueSession.createBytesMessage();
   bytesMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(bytesMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //map
   MapMessage mapMessage = defaultQueueSession.createMapMessage();
   mapMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(mapMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //object
   ObjectMessage objMessage = defaultQueueSession.createObjectMessage();
   objMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(objMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //stream
   StreamMessage streamMessage = defaultQueueSession.createStreamMessage();
   streamMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(streamMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));

   //text
   TextMessage textMessage = defaultQueueSession.createTextMessage();
   textMessage.setStringProperty("testName", "testSendEmptyMessages");
   defaultSender.send(textMessage);
   assertNotNull("Didn't receive message", queueReceiver.receive(1000));
}
 
Example 8
Source File: SessionCache.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private ObjectMessage createMessage(String token, OAuth2Authentication auth, String action) throws JMSException {
    ObjectMessage msg = jmsSession.createObjectMessage(auth);
    msg.setObjectProperty(ACTION_KEY, action);
    msg.setStringProperty(TOKEN_KEY, token);
    return msg;
}