/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setInt(final String name, final int value) throws JMSException { if (ActiveMQRAMapMessage.trace) { ActiveMQRALogger.LOGGER.trace("setInt(" + name + ", " + value + ")"); } ((MapMessage) message).setInt(name, value); }
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Person person = (Person) object; MapMessage message = session.createMapMessage(); message.setString("name", person.getName()); message.setInt("age", person.getAge()); return message; }
public Message toMessage(Object obj, Session session) throws JMSException, MessageConversionException { if (!(obj instanceof OperationLog)) { throw new MessageConversionException("Object isn't a WorkState"); } OperationLog optLog = (OperationLog) obj; MapMessage msg = session.createMapMessage(); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); msg.setInt("mainType", optLog.getMainType().intValue()); msg.setInt("minorType", optLog.getMinorType().intValue()); msg.setInt("ctrlUnitId", optLog.getCtrlUnitId().intValue()); msg.setInt("userId", optLog.getUserId().intValue()); msg.setString("triggerTime", dateFormat.format(optLog.getTriggerTime())); msg.setInt("resourceId", optLog.getResourceId().intValue()); msg.setString("logTxt", optLog.getLogTxt()); return msg; }
/** * @param type * @throws JMSException */ private Object createBodySendAndReceive(JmsMessageType type) throws JMSException { Object res = null; Message msg = null; switch (type) { case BYTE: BytesMessage mByte = queueProducerSession.createBytesMessage(); final int size = 20; byte[] resByte = new byte[size]; for (int i = 0; i < size; i++) { resByte[i] = (byte) i; mByte.writeByte((byte) i); } msg = mByte; res = resByte; break; case TEXT: res = "JMS2"; msg = queueProducerSession.createTextMessage("JMS2"); break; case STREAM: msg = queueProducerSession.createStreamMessage(); break; case OBJECT: res = new Double(37.6); msg = queueProducerSession.createObjectMessage(new Double(37.6)); break; case MAP: MapMessage msg1 = queueProducerSession.createMapMessage(); msg1.setInt("int", 13); msg1.setLong("long", 37L); msg1.setString("string", "crocodile"); msg = msg1; Map<String, Object> map = new HashMap<String, Object>(); map.put("int", Integer.valueOf(13)); map.put("long", Long.valueOf(37L)); map.put("string", "crocodile"); res = map; break; default: Assert.fail("no default..."); } Assert.assertNotNull(msg); msg.setStringProperty("type", type.toString()); queueProducer.send(msg); return res; }
@Override public JMSProducer send(Destination destination, Map<String, Object> body) { MapMessage message = context.createMapMessage(); if (body != null) { try { for (Entry<String, Object> entry : body.entrySet()) { final String name = entry.getKey(); final Object v = entry.getValue(); if (v instanceof String) { message.setString(name, (String) v); } else if (v instanceof Long) { message.setLong(name, (Long) v); } else if (v instanceof Double) { message.setDouble(name, (Double) v); } else if (v instanceof Integer) { message.setInt(name, (Integer) v); } else if (v instanceof Character) { message.setChar(name, (Character) v); } else if (v instanceof Short) { message.setShort(name, (Short) v); } else if (v instanceof Boolean) { message.setBoolean(name, (Boolean) v); } else if (v instanceof Float) { message.setFloat(name, (Float) v); } else if (v instanceof Byte) { message.setByte(name, (Byte) v); } else if (v instanceof byte[]) { byte[] array = (byte[]) v; message.setBytes(name, array, 0, array.length); } else { message.setObject(name, v); } } } catch (JMSException e) { throw new MessageFormatRuntimeException(e.getMessage()); } } send(destination, message); return this; }
public static void main(String[] args) { MapMessage outMessage; JMSConsumer orderConfirmReceiver; MapMessage inMessage; if (args.length != 1) { System.out.println("Error: Program takes numerical argument."); System.exit(1); } quantity = (new Integer(args[0])).intValue(); System.out.println("Retailer: Quantity to be ordered is " + quantity); /* * Create non-transacted context and sender for * vendor order queue. * Create message to vendor, setting item and * quantity values. * Send message. * Create receiver for retailer confirmation queue. * Get message and report result. * Send an end-of-message-stream message so vendor * will stop processing orders. */ try (JMSContext context = connectionFactory.createContext(); ) { outMessage = context.createMapMessage(); outMessage.setString("Item", "Computer(s)"); outMessage.setInt("Quantity", quantity); outMessage.setJMSReplyTo(retailerConfirmQueue); context.createProducer().send(vendorOrderQueue, outMessage); System.out.println("Retailer: Ordered " + quantity + " computer(s)"); orderConfirmReceiver = context.createConsumer(retailerConfirmQueue); inMessage = (MapMessage) orderConfirmReceiver.receive(); if (inMessage.getBoolean("OrderAccepted") == true) { System.out.println("Retailer: Order filled"); } else { System.out.println("Retailer: Order not filled"); } System.out.println("Retailer: Placing another order"); outMessage.setInt("Quantity", quantity * 2); context.createProducer().send(vendorOrderQueue, outMessage); System.out.println("Retailer: Ordered " + outMessage.getInt("Quantity") + " computer(s)"); inMessage = (MapMessage) orderConfirmReceiver.receive(); if (inMessage.getBoolean("OrderAccepted") == true) { System.out.println("Retailer: Order filled"); } else { System.out.println("Retailer: Order not filled"); } /* * Send a non-text control message indicating end * of messages. */ context.createProducer().send(vendorOrderQueue, context.createMessage()); } catch (JMSException e) { System.err.println("Retailer: Exception occurred: " + e.toString()); } }