List of usage examples for javax.jms MessageProducer send
void send(Message message) throws JMSException;
From source file:eu.domibus.submission.jms.BackendJMSImpl.java
/** * This method checks for pending messages received by another gateway and processes them to a JMS destination * * @param ctx//from w ww . j av a 2 s .co m */ public void executeInternal(final JobExecutionContext ctx) { try { final Collection<String> ids = this.messageRetriever.listPendingMessages(); if (!ids.isEmpty() || ids.size() > 0) { final String[] messageIds = ids.toArray(new String[ids.size()]); Connection connection; MessageProducer producer; connection = this.cf.createConnection(); for (final String messageId : messageIds) { final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(this.receivingQueue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); final MapMessage resMessage = session.createMapMessage(); this.downloadMessage(messageId, resMessage); producer.send(resMessage); producer.close(); session.close(); } connection.close(); } else { BackendJMSImpl.LOG.debug("No pending messages to send"); } } catch (final JMSException | ValidationException ex) { BackendJMSImpl.LOG.error(ex); } }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
protected void publishTestTopicMessages(int publishSize, int deliveryMode, AtomicLong publishedMessageSize) throws Exception { // create a new queue Connection connection = cf.createConnection(); connection.setClientID("clientId2"); connection.start();// w w w . j a v a 2 s.c om // Start the connection Session session = connection.createSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = session.createTopic(defaultTopicName); try { // publish a bunch of non-persistent messages to fill up the temp // store MessageProducer prod = session.createProducer(topic); prod.setDeliveryMode(deliveryMode); for (int i = 0; i < publishSize; i++) { prod.send( createMessage(i, session, JournalPendingMessageTest.maxMessageSize, publishedMessageSize)); } } finally { connection.close(); } }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * @param order - Order to be placed/* w w w .j a v a2 s . c o m*/ * @param ttl - Time to live. Set to 0 for indefinite * @param deliveryMode - Set to 1 for non-persistent. Default 0 */ public void publishOrder(Order order, MessageProducer mp) { BytesMessage orderMessage; try { Session session = this.createSession(); // Create a new ByteMessage orderMessage = session.createBytesMessage(); // Serialize the tick content into the message orderMessage.writeBytes(order.serialize()); orderMessage.setStringProperty("Symbol", order.getSymbol()); mp.send(orderMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.activemq.bugs.AMQ7067Test.java
@Test public void testRollback() throws Exception { final Connection connection = ACTIVE_MQ_NON_XA_CONNECTION_FACTORY.createConnection(); connection.start();/*from ww w .j av a 2 s .co m*/ Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue holdKahaDb = session.createQueue("holdKahaDb"); MessageProducer holdKahaDbProducer = session.createProducer(holdKahaDb); TextMessage helloMessage = session.createTextMessage(StringUtils.repeat("a", 10)); holdKahaDbProducer.send(helloMessage); Queue queue = session.createQueue("test"); produce(connection, queue, 100, 512 * 1024); session.rollback(); produce(connection, queue, 100, 512 * 1024); System.out.println(String.format("QueueSize %s: %d", holdKahaDb.getQueueName(), getQueueSize(holdKahaDb.getQueueName()))); purgeQueue(queue.getQueueName()); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == getQueueSize(queue.getQueueName()); } }); // force gc broker.getPersistenceAdapter().checkpoint(true); connection.close(); curruptIndexFile(getDataDirectory()); broker.stop(); broker.waitUntilStopped(); createBroker(); broker.waitUntilStarted(); // no sign of the test queue on recovery, rollback is the default for any inflight // this test serves as a sanity check on existing behaviour try { getQueueSize(holdKahaDb.getQueueName()); fail("expect InstanceNotFoundException"); } catch (UndeclaredThrowableException expected) { assertTrue(expected.getCause() instanceof InstanceNotFoundException); } }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * @param tickSize//from ww w. j a va 2 s.c om * @param ttl * @param persistent */ public void publishTickSize(TickSize tickSize, MessageProducer mp) { BytesMessage tickMessage; try { Session session = this.createSession(); // Create a new ByteMessage tickMessage = session.createBytesMessage(); // Serialize the tick content into the message tickMessage.writeBytes(tickSize.serialize()); tickMessage.setStringProperty("Symbol", tickSize.getSymbol()); mp.send(tickMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.apache.activemq.bugs.AMQ7067Test.java
@Test public void testCommit() throws Exception { final Connection connection = ACTIVE_MQ_NON_XA_CONNECTION_FACTORY.createConnection(); connection.start();//from ww w .jav a2s . c o m Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue holdKahaDb = session.createQueue("holdKahaDb"); MessageProducer holdKahaDbProducer = session.createProducer(holdKahaDb); TextMessage helloMessage = session.createTextMessage(StringUtils.repeat("a", 10)); holdKahaDbProducer.send(helloMessage); Queue queue = session.createQueue("test"); produce(connection, queue, 100, 512 * 1024); session.commit(); produce(connection, queue, 100, 512 * 1024); System.out.println(String.format("QueueSize %s: %d", holdKahaDb.getQueueName(), getQueueSize(holdKahaDb.getQueueName()))); purgeQueue(queue.getQueueName()); Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisified() throws Exception { return 0 == getQueueSize(queue.getQueueName()); } }); // force gc broker.getPersistenceAdapter().checkpoint(true); connection.close(); curruptIndexFile(getDataDirectory()); broker.stop(); broker.waitUntilStopped(); createBroker(); broker.waitUntilStarted(); while (true) { try { TimeUnit.SECONDS.sleep(1); System.out.println(String.format("QueueSize %s: %d", holdKahaDb.getQueueName(), getQueueSize(holdKahaDb.getQueueName()))); break; } catch (Exception ex) { System.out.println(ex.getMessage()); break; } } // THIS SHOULD NOT FAIL AS THERE SHOULD BE ONLY 1 TRANSACTION! assertEquals(1, getQueueSize(holdKahaDb.getQueueName())); }
From source file:com.bitsofproof.supernode.core.ImplementBCSAPI.java
private void reply(Destination destination, byte[] msg) { MessageProducer replier = null; try {// w ww . j a va 2s. co m replier = session.createProducer(destination); BytesMessage m = session.createBytesMessage(); if (msg != null) { m.writeBytes(msg); } replier.send(m); } catch (JMSException e) { log.trace("can not reply", e); } finally { try { replier.close(); } catch (JMSException e) { } } }
From source file:Vendor.java
public void onMessage(Message message) { if (!(message instanceof MapMessage)) { synchronized (supplierLock) { numSuppliers--;/*from w w w. j a v a2 s.c o m*/ supplierLock.notifyAll(); } try { asyncSession.commit(); return; } catch (JMSException e) { e.printStackTrace(); } } int orderNumber = -1; try { MapMessage componentMessage = (MapMessage) message; orderNumber = componentMessage.getInt("VendorOrderNumber"); Order order = Order.getOrder(orderNumber); order.processSubOrder(componentMessage); asyncSession.commit(); if (!"Pending".equals(order.getStatus())) { System.out.println("Vendor: Completed processing for order " + orderNumber); MessageProducer replyProducer = asyncSession.createProducer(order.getMessage().getJMSReplyTo()); MapMessage replyMessage = asyncSession.createMapMessage(); if ("Fulfilled".equals(order.getStatus())) { replyMessage.setBoolean("OrderAccepted", true); System.out.println("Vendor: sent " + order.quantity + " computer(s)"); } else { replyMessage.setBoolean("OrderAccepted", false); System.out.println("Vendor: unable to send " + order.quantity + " computer(s)"); } replyProducer.send(replyMessage); asyncSession.commit(); System.out.println("Vender: committed transaction 2"); } } catch (JMSException e) { e.printStackTrace(); } }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testQueueLargeMessageSizeTX() throws Exception { ActiveMQConnectionFactory acf = (ActiveMQConnectionFactory) cf; acf.setMinLargeMessageSize(1000);/* www. j a va 2 s .com*/ Connection connection = cf.createConnection(); connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); String testText = StringUtils.repeat("t", 2000); MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName)); ActiveMQTextMessage message = (ActiveMQTextMessage) session.createTextMessage(testText); for (int i = 0; i < 10; i++) { producer.send(message); } //not commited so should be 0 verifyPendingStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10); verifyPendingDurableStats(defaultQueueName, 0, message.getCoreMessage().getPersistentSize() * 10); session.commit(); verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10); verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize() * 10); connection.close(); this.killServer(); this.restartServer(); verifyPendingStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize()); verifyPendingDurableStats(defaultQueueName, 10, message.getCoreMessage().getPersistentSize()); }
From source file:org.mot.common.mq.ActiveMQFactory.java
/** * @param tick// w w w .jav a 2s.c o m * @param ttl * @param persistent */ public void publishTick(Tick tick, MessageProducer mp) { BytesMessage tickMessage; try { Session session = this.createSession(); // Create a new ByteMessage tickMessage = session.createBytesMessage(); // Serialize the tick content into the message tickMessage.writeBytes(tick.serialize()); tickMessage.setStringProperty("Symbol", tick.getSymbol()); tickMessage.setStringProperty("Currency", tick.getCurrency()); mp.send(tickMessage); this.closeSession(session); } catch (JMSException e) { // TODO Auto-generated catch block e.printStackTrace(); } }