Java Code Examples for javax.jms.TextMessage#setBooleanProperty()

The following examples show how to use javax.jms.TextMessage#setBooleanProperty() . 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: JmsSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithString() throws JMSException {
    WeldContainer container = prepare();

    RawMessageConsumerBean bean = container.select(RawMessageConsumerBean.class).get();
    assertThat(bean.messages()).isEmpty();

    Queue q = jms.createQueue("queue-one");
    JMSProducer producer = jms.createProducer();
    TextMessage message = jms.createTextMessage("hello");
    message.setStringProperty("string", "value");
    message.setBooleanProperty("bool", true);
    message.setLongProperty("long", 100L);
    message.setByteProperty("byte", (byte) 5);
    message.setFloatProperty("float", 5.5f);
    message.setDoubleProperty("double", 10.3);
    message.setIntProperty("int", 23);
    message.setObjectProperty("object", "yop");
    message.setShortProperty("short", (short) 3);
    producer.send(q, message);

    await().until(() -> bean.messages().size() == 1);
    IncomingJmsMessage<?> incomingJmsMessage = bean.messages().get(0);
    IncomingJmsMessageMetadata metadata = incomingJmsMessage.getMetadata(IncomingJmsMessageMetadata.class)
            .orElseThrow(() -> new AssertionError("Metadata expected"));
    assertThat(incomingJmsMessage.getPayload()).isEqualTo("hello");
    assertThat(metadata.getBody(String.class)).isEqualTo("hello");
    assertThat(metadata.propertyExists("string")).isTrue();
    assertThat(metadata.propertyExists("missing")).isFalse();
    assertThat(metadata.getStringProperty("string")).isEqualTo("value");
    assertThat(metadata.getBooleanProperty("bool")).isTrue();
    assertThat(metadata.getLongProperty("long")).isEqualTo(100L);
    assertThat(metadata.getByteProperty("byte")).isEqualTo((byte) 5);
    assertThat(metadata.getFloatProperty("float")).isEqualTo(5.5f);
    assertThat(metadata.getDoubleProperty("double")).isEqualTo(10.3);
    assertThat(metadata.getIntProperty("int")).isEqualTo(23);
    assertThat(metadata.getObjectProperty("object")).isInstanceOf(String.class);
    assertThat(((String) message.getObjectProperty("object"))).isEqualTo("yop");
    assertThat(message.getShortProperty("short")).isEqualTo((short) 3);
}
 
Example 2
Source File: TradeSLSBBean.java    From sample.daytrader7 with Apache License 2.0 5 votes vote down vote up
@Override
public void queueOrder(Integer orderID, boolean twoPhase) {
    if (Log.doTrace()) {
        Log.trace("TradeSLSBBean:queueOrder", orderID);
    }
            	
    if (TradeConfig.getOrderProcessingMode() == TradeConfig.ASYNCH_MANAGEDTHREAD) {
    
        Thread thread = managedThreadFactory.newThread(new CompleteOrderThread(orderID, twoPhase));
        
        thread.start();
    
    } else {
    
        try (JMSContext queueContext = queueConnectionFactory.createContext();) {
            TextMessage message = queueContext.createTextMessage();

            message.setStringProperty("command", "neworder");
            message.setIntProperty("orderID", orderID);
            message.setBooleanProperty("twoPhase", twoPhase);
            message.setText("neworder: orderID=" + orderID + " runtimeMode=EJB twoPhase=" + twoPhase);
            message.setLongProperty("publishTime", System.currentTimeMillis());
    		        		
            queueContext.createProducer().send(tradeBrokerQueue, message);
    		
        } catch (Exception e) {
            throw new EJBException(e.getMessage(), e); // pass the exception
        }
    }
}
 
Example 3
Source File: QueueReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
   QueueConnection qc = null;

   try {
      qc = createQueueConnection();
      QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");

      qc.start();

      TextMessage m = qs.createTextMessage();
      m.setText("one");
      m.setBooleanProperty("targetMessage", false);

      QueueSender qsender = qs.createSender(queue1);

      qsender.send(m);

      m.setText("two");
      m.setBooleanProperty("targetMessage", true);

      qsender.send(m);

      TextMessage rm = (TextMessage) qreceiver.receive(1000);

      ProxyAssertSupport.assertEquals("two", rm.getText());
   } finally {
      if (qc != null) {
         qc.close();
      }
      Thread.sleep(2000);
      removeAllMessages(queue1.getQueueName(), true);
      checkEmpty(queue1);
   }
}
 
Example 4
Source File: JMSEventMarshaller.java    From cougar with Apache License 2.0 5 votes vote down vote up
@Override
public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException {
    try {
        TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event));

        //Sets the routing string
        message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event));

        //Sets the message id guid.  If there isn't one, make one up
        String messageId = event.getMessageId();
        if (messageId == null) {
            messageId = new RequestUUIDImpl().toString();
        }
        message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId);

        //Sets the version header
        message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString());

        //Sets the event name header
        message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName());

        message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true);
        message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered",   true);
        message.setJMSDeliveryMode(deliveryMode);
        message.setJMSExpiration(expirationTime);
        message.setJMSPriority(priority);

        return message;
    } catch (JMSException jmsex) {
        throw new CougarFrameworkException("Error marshalling Event", jmsex);
    } catch (UnknownHostException e) {
        throw new CougarFrameworkException("Error looking up local host name", e);
    }
}
 
Example 5
Source File: PropertyFilterTest.java    From brave with Apache License 2.0 5 votes vote down vote up
static void setAllPropertyTypes(TextMessage message) throws JMSException {
  message.setBooleanProperty("boolean", true);
  message.setByteProperty("byte", Byte.MAX_VALUE);
  message.setDoubleProperty("double", Double.MIN_VALUE);
  message.setFloatProperty("float", Float.MIN_VALUE);
  message.setIntProperty("int", Integer.MIN_VALUE);
  message.setLongProperty("long", Long.MIN_VALUE);
  message.setObjectProperty("object", Collections.emptyMap());
  message.setShortProperty("short", Short.MIN_VALUE);
  message.setStringProperty("string", "string");
}
 
Example 6
Source File: JmsPropertyTypeTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testBooleanProperty(String port,
                                String adminUsername,
                                String adminPassword,
                                String brokerHostname) throws NamingException, JMSException {
    String queueName = "testBooleanProperty";

    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // send messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);
    String booleanPropertyName1 = "BooleanProperty1";
    String booleanPropertyName2 = "BooleanProperty2";
    TextMessage textMessage = producerSession.createTextMessage("Test message");
    textMessage.setBooleanProperty(booleanPropertyName1, true);
    textMessage.setBooleanProperty(booleanPropertyName2, false);
    producer.send(textMessage);
    producerSession.close();

    // receive messages
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    TextMessage message = (TextMessage) consumer.receive(1000);
    Assert.assertNotNull(message, "Message was not received");
    boolean receivedBooleanProperty1 = message.getBooleanProperty(booleanPropertyName1);
    boolean receivedBooleanProperty2 = message.getBooleanProperty(booleanPropertyName2);
    Assert.assertEquals(true, receivedBooleanProperty1, "Boolean property not matched.");
    Assert.assertEquals(false, receivedBooleanProperty2, "Boolean property not matched.");

    subscriberSession.close();
    connection.close();
}
 
Example 7
Source File: JmsTopicSelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void sendMessages() throws Exception {
   TextMessage message = session.createTextMessage("1");
   message.setIntProperty("id", 1);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("2");
   message.setIntProperty("id", 2);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("3");
   message.setIntProperty("id", 3);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("4");
   message.setIntProperty("id", 4);
   message.setJMSType("b");
   message.setStringProperty("stringProperty", "b");
   message.setLongProperty("longProperty", 2);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("5");
   message.setIntProperty("id", 5);
   message.setJMSType("c");
   message.setStringProperty("stringProperty", "c");
   message.setLongProperty("longProperty", 3);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);
}
 
Example 8
Source File: MQTTOpenwireTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void doTestSendJMSReceiveMQTT(String jmsDestination, String mqttTopic) throws Exception {
   final MQTTClientProvider provider = getMQTTClientProvider();
   initializeConnection(provider);

   ActiveMQConnection activeMQConnection = (ActiveMQConnection) cf.createConnection();
   try {
      activeMQConnection.setUseRetroactiveConsumer(true);
      activeMQConnection.start();
      Session s = activeMQConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      javax.jms.Topic jmsTopic = s.createTopic(jmsDestination);
      MessageProducer producer = s.createProducer(jmsTopic);

      final String RETAINED = "RETAINED";
      provider.subscribe(mqttTopic, AT_MOST_ONCE);

      // send retained message from JMS
      TextMessage sendMessage = s.createTextMessage(RETAINED);
      // mark the message to be retained
      sendMessage.setBooleanProperty("ActiveMQ.Retain", true);
      // MQTT QoS can be set using MQTTProtocolConverter.QOS_PROPERTY_NAME property
      sendMessage.setIntProperty("ActiveMQ.MQTT.QoS", 0);
      producer.send(sendMessage);

      byte[] message = provider.receive(2000);
      assertNotNull("Should get retained message " + jmsDestination + "->" + mqttTopic, message);
      assertEquals(RETAINED, new String(message));

      for (int i = 0; i < 1; i++) {
         String payload = "This is Test Message: " + i;
         sendMessage = s.createTextMessage(payload);
         producer.send(sendMessage);
         message = provider.receive(1000);
         assertNotNull("Should get a message " + jmsDestination + "->" + mqttTopic, message);

         assertEquals(payload, new String(message));
      }
   } finally {
      activeMQConnection.close();
      provider.disconnect();
   }
}
 
Example 9
Source File: JmsTopicSelectorTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void sendMessages() throws Exception {
   TextMessage message = session.createTextMessage("1");
   message.setIntProperty("id", 1);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("2");
   message.setIntProperty("id", 2);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("3");
   message.setIntProperty("id", 3);
   message.setJMSType("a");
   message.setStringProperty("stringProperty", "a");
   message.setLongProperty("longProperty", 1);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);

   message = session.createTextMessage("4");
   message.setIntProperty("id", 4);
   message.setJMSType("b");
   message.setStringProperty("stringProperty", "b");
   message.setLongProperty("longProperty", 2);
   message.setBooleanProperty("booleanProperty", false);
   producer.send(message);

   message = session.createTextMessage("5");
   message.setIntProperty("id", 5);
   message.setJMSType("c");
   message.setStringProperty("stringProperty", "c");
   message.setLongProperty("longProperty", 3);
   message.setBooleanProperty("booleanProperty", true);
   producer.send(message);
}
 
Example 10
Source File: RequestReplyToTopicViaThreeNetworkHopsTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
public void testMessages(Session sess,
                         MessageProducer req_prod,
                         Destination resp_dest,
                         int num_msg) throws Exception {
   MessageConsumer resp_cons;
   TextMessage msg;
   MessageClient cons_client;
   int cur;
   int tot_expected;

   resp_cons = sess.createConsumer(resp_dest);

   cons_client = new MessageClient(resp_cons, num_msg);
   cons_client.start();

   cur = 0;
   while ((cur < num_msg) && (!fatalTestError)) {
      msg = sess.createTextMessage("MSG AAAA " + cur);
      msg.setIntProperty("SEQ", 100 + cur);
      msg.setStringProperty("TEST", "TOPO");
      msg.setJMSReplyTo(resp_dest);

      if (cur == (num_msg - 1))
         msg.setBooleanProperty("end-of-response", true);

      sendWithRetryOnDeletedDest(req_prod, msg);
      LOG.debug("Sent:" + msg);

      cur++;
   }

   //
   // Give the consumer some time to receive the response.
   //
   cons_client.waitShutdown(5000);

   //
   // Now shutdown the consumer if it's still running.
   //
   if (cons_client.shutdown())
      LOG.debug("Consumer client shutdown complete");
   else
      LOG.debug("Consumer client shutdown incomplete!!!");

   //
   // Check that the correct number of messages was received.
   //
   tot_expected = num_msg * (echoResponseFill + 1);

   if (cons_client.getNumMsgReceived() == tot_expected) {
      LOG.debug("Have " + tot_expected + " messages, as-expected");
   } else {
      testError = true;

      if (cons_client.getNumMsgReceived() == 0)
         fatalTestError = true;

      LOG.error("Have " + cons_client.getNumMsgReceived() + " messages; expected " + tot_expected + " on destination " + resp_dest);
   }

   resp_cons.close();
}