List of usage examples for javax.jms MapMessage getBoolean
boolean getBoolean(String name) throws JMSException;
From source file:Retailer.java
public void run() { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url); try {/*from ww w . ja va 2 s.c o m*/ Connection connection = connectionFactory.createConnection(); // The Retailer's session is non-trasacted. Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination vendorOrderQueue = session.createQueue("VendorOrderQueue"); TemporaryQueue retailerConfirmQueue = session.createTemporaryQueue(); MessageProducer producer = session.createProducer(vendorOrderQueue); MessageConsumer replyConsumer = session.createConsumer(retailerConfirmQueue); connection.start(); for (int i = 0; i < 5; i++) { MapMessage message = session.createMapMessage(); message.setString("Item", "Computer(s)"); int quantity = (int) (Math.random() * 4) + 1; message.setInt("Quantity", quantity); message.setJMSReplyTo(retailerConfirmQueue); producer.send(message); System.out.println("Retailer: Ordered " + quantity + " computers."); MapMessage reply = (MapMessage) replyConsumer.receive(); if (reply.getBoolean("OrderAccepted")) { System.out.println("Retailer: Order Filled"); } else { System.out.println("Retailer: Order Not Filled"); } } // Send a non-MapMessage to signal the end producer.send(session.createMessage()); replyConsumer.close(); connection.close(); } catch (JMSException e) { e.printStackTrace(); } }
From source file:org.gss_project.gss.server.ejb.indexer.IndexerMDBean.java
/** * Decides to add or drop an item from the index depending on the message * received//from w ww.j ava2s . com * * It currently uses the patched solr API for rich documents. This API does not * allow indexing time field boosting. For this reason we have to use the dismax search API (instead of the * standard) that allows for search time field boosting * * @param msg * @see javax.jms.MessageListener#onMessage(javax.jms.Message) */ @Override public void onMessage(Message msg) { Long id = null; try { MapMessage map = (MapMessage) msg; id = (Long) map.getObject("id"); boolean delete = map.getBoolean("delete"); if (delete) { CommonsHttpSolrServer solr = new CommonsHttpSolrServer(getConfiguration().getString("solr.url")); sendDelete(solr, id); solr.commit(); } else { service.postFileToSolr(id); } } catch (JMSException e) { throw new EJBException("Error processing file ID " + id, e); } catch (IOException e) { throw new EJBException("Error processing file ID " + id, e); } catch (SolrServerException e) { throw new EJBException(e); } catch (ObjectNotFoundException e) { throw new EJBException(e); } }
From source file:org.mule.transport.jms.JmsMessageUtilsTestCase.java
/** * Tests that is able to convert a Map which only contains simple values into a * MapMessage./*from w w w . ja va2s. c om*/ */ @Test public void testConvertsValidMapWithSimpleValuesToMapMessage() throws JMSException { Session session = mock(Session.class); when(session.createMapMessage()).thenReturn(new ActiveMQMapMessage()); // Creates a test Map with data Map data = new HashMap(); data.put("value1", new Float(4)); data.put("value2", new byte[] { 1, 2, 3 }); data.put("value3", "value3"); data.put("value4", new Double(67.9)); data.put("value5", true); data.put("value6", null); Message message = JmsMessageUtils.toMessage(data, session); assertTrue(message instanceof MapMessage); MapMessage mapMessage = (MapMessage) message; assertEquals(new Float(4), mapMessage.getFloat("value1"), 0); assertTrue(Arrays.equals(new byte[] { 1, 2, 3 }, mapMessage.getBytes("value2"))); assertEquals("value3", mapMessage.getString("value3")); assertEquals(new Double(67.9), mapMessage.getDouble("value4"), 0); assertTrue(mapMessage.getBoolean("value5")); assertNull(mapMessage.getObject("value6")); }