Java Code Examples for javax.jms.TextMessage#setLongProperty()
The following examples show how to use
javax.jms.TextMessage#setLongProperty() .
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: SelectorTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Test the "<>" (not equal) condition in message selector. * <br /> * <ul> * <li><code>"weight <> 2500"</code> is <code>true</code> for 1000 and <code>false</code> for 2500</li> * </ul> */ @Test public void testNotEquals() throws Exception { if (receiver != null) { receiver.close(); } receiver = receiverSession.createReceiver(receiverQueue, "weight <> 2500"); TextMessage dummyMessage = senderSession.createTextMessage(); dummyMessage.setLongProperty("weight", 2500); dummyMessage.setText("testEquals:1"); sender.send(dummyMessage); TextMessage message = senderSession.createTextMessage(); message.setLongProperty("weight", 1000); message.setText("testEquals:2"); sender.send(message); TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT); Assert.assertEquals("testEquals:2", msg.getText()); }
Example 2
Source File: SelectorTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Test the ">" condition in message selector. * <br /> * <ul> * <li><code>"weight > 2500"</code> is <code>true</code> for 3000 and <code>false</code> for 1000</li> * </ul> */ @Test public void testGreaterThan() throws Exception { if (receiver != null) { receiver.close(); } receiver = receiverSession.createReceiver(receiverQueue, "weight > 2500"); TextMessage dummyMessage = senderSession.createTextMessage(); dummyMessage.setLongProperty("weight", 1000); dummyMessage.setText("testGreaterThan:1"); sender.send(dummyMessage); TextMessage message = senderSession.createTextMessage(); message.setLongProperty("weight", 3000); message.setText("testGreaterThan:2"); sender.send(message); TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT); Assert.assertEquals("testGreaterThan:2", msg.getText()); }
Example 3
Source File: SelectorTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Test the message selector using the filter example provided by the JMS specifications. * <br /> * <ul> * <li><code>"JMSType = 'car' AND color = 'blue' AND weight > 2500"</code></li> * </ul> */ @Test public void testSelectorExampleFromSpecs() throws Exception { if (receiver != null) { receiver.close(); } receiver = receiverSession.createReceiver(receiverQueue, "JMSType = 'car' AND color = 'blue' AND weight > 2500"); TextMessage dummyMessage = senderSession.createTextMessage(); dummyMessage.setJMSType("car"); dummyMessage.setStringProperty("color", "red"); dummyMessage.setLongProperty("weight", 3000); dummyMessage.setText("testSelectorExampleFromSpecs:1"); sender.send(dummyMessage); TextMessage message = senderSession.createTextMessage(); message.setJMSType("car"); message.setStringProperty("color", "blue"); message.setLongProperty("weight", 3000); message.setText("testSelectorExampleFromSpecs:2"); sender.send(message); TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT); Assert.assertEquals("testSelectorExampleFromSpecs:2", msg.getText()); }
Example 4
Source File: SelectorTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
/** * Test the "=" condition in message selector. * <br /> * <ul> * <li><code>"weight = 2500"</code> is <code>true</code> for 2500 and <code>false</code> for 1000</li> * </ul> */ @Test public void testEquals() throws Exception { if (receiver != null) { receiver.close(); } receiver = receiverSession.createReceiver(receiverQueue, "weight = 2500"); TextMessage dummyMessage = senderSession.createTextMessage(); dummyMessage.setLongProperty("weight", 1000); dummyMessage.setText("testEquals:1"); sender.send(dummyMessage); TextMessage message = senderSession.createTextMessage(); message.setLongProperty("weight", 2500); message.setText("testEquals:2"); sender.send(message); TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT); Assert.assertEquals("testEquals:2", msg.getText()); }
Example 5
Source File: OpsEventPublisher.java From oneops with Apache License 2.0 | 6 votes |
/** * Publish ci state message. * * @param event the event */ public void publishCiStateMessage(CiChangeStateEvent event) { try { TextMessage message = session.createTextMessage(gson.toJson(event)); message.setLongProperty("ciId", event.getCiId()); message.setStringProperty("type", "ci-change-state"); message.setStringProperty("ciState", event.getNewState()); producer.send(message); logger.info("Published: ciId:" + event.getCiId()); logger.info(message.getText()); } catch (JMSException e) { // TODO see if we can put some durability here logger.error("caught Exception publishing",e); } }
Example 6
Source File: MonitorPublisher.java From oneops with Apache License 2.0 | 6 votes |
private void publishMonitor(MonitorRequest mr) throws SensorClientException { try { TextMessage message = null; message = session.createTextMessage(gson.toJson(mr)); message.setStringProperty(MSG_TYPE, MSG_TYPE_MONITOR); message.setLongProperty(MSG_PROP_MANIFEST_ID, mr.getManifestId()); message.setLongProperty(MSG_PROP_CI_ID, mr.getCiId()); producer.send(message); logger.info("Published: monitor for ciId:" + mr.getCiId() + "; manifestId:" + mr.getManifestId() + "; action:" + mr.getAction()); logger.debug(message.getText()); } catch (JMSException e) { logger.error("caught Exception publishing",e); throw new SensorClientException(e); } }
Example 7
Source File: AbstractPublisherJMS.java From hawkular-apm with Apache License 2.0 | 5 votes |
/** * This method publishes the supplied items. * * @param tenantId The tenant id * @param items The items * @param subscriber The optional subscriber name * @param retryCount The retry count * @param delay The delay * @throws Exception Failed to publish */ protected void doPublish(String tenantId, List<T> items, String subscriber, int retryCount, long delay) throws Exception { String data = mapper.writeValueAsString(items); TextMessage tm = session.createTextMessage(data); if (tenantId != null) { tm.setStringProperty("tenant", tenantId); } if (subscriber != null) { tm.setStringProperty("subscriber", subscriber); } tm.setIntProperty("retryCount", retryCount); if (delay > 0) { tm.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + delay); } if (log.isLoggable(Level.FINEST)) { log.finest("Publish: " + tm); } producer.send(tm); }
Example 8
Source File: TradeSLSBBean.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
@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 9
Source File: TradeSLSBBean.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public void publishQuotePriceChange(QuoteDataBean quote, BigDecimal oldPrice, BigDecimal changeFactor, double sharesTraded) { if (!TradeConfig.getPublishQuotePriceChange()) { return; } if (Log.doTrace()) { Log.trace("TradeSLSBBean:publishQuotePricePublishing -- quoteData = " + quote); } try (JMSContext topicContext = topicConnectionFactory.createContext();) { TextMessage message = topicContext.createTextMessage(); message.setStringProperty("command", "updateQuote"); message.setStringProperty("symbol", quote.getSymbol()); message.setStringProperty("company", quote.getCompanyName()); message.setStringProperty("price", quote.getPrice().toString()); message.setStringProperty("oldPrice", oldPrice.toString()); message.setStringProperty("open", quote.getOpen().toString()); message.setStringProperty("low", quote.getLow().toString()); message.setStringProperty("high", quote.getHigh().toString()); message.setDoubleProperty("volume", quote.getVolume()); message.setStringProperty("changeFactor", changeFactor.toString()); message.setDoubleProperty("sharesTraded", sharesTraded); message.setLongProperty("publishTime", System.currentTimeMillis()); message.setText("Update Stock price for " + quote.getSymbol() + " old price = " + oldPrice + " new price = " + quote.getPrice()); topicContext.createProducer().send(tradeStreamerTopic, message); } catch (Exception e) { throw new EJBException(e.getMessage(), e); // pass the exception } }
Example 10
Source File: PropertyFilterTest.java From brave with Apache License 2.0 | 5 votes |
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 11
Source File: TradeDirect.java From sample.daytrader7 with Apache License 2.0 | 5 votes |
private void publishQuotePriceChange(QuoteDataBean quoteData, BigDecimal oldPrice, BigDecimal changeFactor, double sharesTraded) throws Exception { if (Log.doTrace()) { Log.trace("TradeDirect:publishQuotePrice PUBLISHING to MDB quoteData = " + quoteData); } try (JMSContext context = tConnFactory.createContext();){ TextMessage message = context.createTextMessage(); message.setStringProperty("command", "updateQuote"); message.setStringProperty("symbol", quoteData.getSymbol()); message.setStringProperty("company", quoteData.getCompanyName()); message.setStringProperty("price", quoteData.getPrice().toString()); message.setStringProperty("oldPrice", oldPrice.toString()); message.setStringProperty("open", quoteData.getOpen().toString()); message.setStringProperty("low", quoteData.getLow().toString()); message.setStringProperty("high", quoteData.getHigh().toString()); message.setDoubleProperty("volume", quoteData.getVolume()); message.setStringProperty("changeFactor", changeFactor.toString()); message.setDoubleProperty("sharesTraded", sharesTraded); message.setLongProperty("publishTime", System.currentTimeMillis()); message.setText("Update Stock price for " + quoteData.getSymbol() + " old price = " + oldPrice + " new price = " + quoteData.getPrice()); context.createProducer().send(streamerTopic, message); } catch (Exception e) { throw e; // pass exception back } }
Example 12
Source File: SchedulerDBVersionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void scheduleRepeating(Connection connection) throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("test.queue"); MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage("test msg"); long time = 1000; message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 500); message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, -1); producer.send(message); producer.close(); }
Example 13
Source File: JobSchedulerJmxManagementTests.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected void scheduleMessage(int time, int period, int repeat) throws Exception { Connection connection = createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("test msg"); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, period); message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, repeat); producer.send(message); connection.close(); }
Example 14
Source File: JobSchedulerManagementTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
protected void scheduleMessage(Connection connection, long delay, int count) throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("test msg"); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay); for (int i = 0; i < count; ++i) { producer.send(message); } producer.close(); }
Example 15
Source File: JmsSchedulerTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testScheduleRestart() throws Exception { // send a message Connection connection = createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage("test msg"); long time = 5000; message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); producer.send(message); producer.close(); //restart broker broker.stop(); broker.waitUntilStopped(); broker = createBroker(false); broker.start(); broker.waitUntilStarted(); // consume the message connection = createConnection(); connection.start(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = session.createConsumer(destination); Message msg = consumer.receive(5000); assertNotNull("Didn't receive the message", msg); //send another message producer = session.createProducer(destination); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); producer.send(message); producer.close(); }
Example 16
Source File: KahaDBSchedulerIndexRebuildTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void scheduleRepeating(Connection connection) throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("test.queue"); MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage("test msg"); long time = 360 * 1000; message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 500); message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, -1); producer.send(message); producer.close(); }
Example 17
Source File: KahaDBSchedulerIndexRebuildTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void scheduleOneShot(Connection connection) throws Exception { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("test.queue"); MessageProducer producer = session.createProducer(queue); TextMessage message = session.createTextMessage("test msg"); long time = TimeUnit.SECONDS.toMillis(30); message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time); message.setIntProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 0); producer.send(message); producer.close(); }
Example 18
Source File: JmsSourceTest.java From smallrye-reactive-messaging with Apache License 2.0 | 5 votes |
@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 19
Source File: JmsTopicSelectorTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
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 20
Source File: JmsTopicSelectorTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
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); }