public Message createMessage(Session session) throws JMSException { MapMessage msg = session.createMapMessage(); msg.setString("JID", JID); msg.setString("URL", URL); msg.setString("DESC", DESC); return msg; }
@PreRemove void onPreRemove(Object entity) { String entityName = entity.getClass().getName(); if (TrackedEntityUtils.isTrackedEntity(entityName)) { try { Session session = createSession(); MapMessage message = session.createMapMessage(); message.setLong("time", System.currentTimeMillis()); message.setString("entity", entityName); message.setString("eventType", EventType.Delete.name()); message.setObject("id", getEntityId(entity)); Long loggedUserId = getLoggedUserId(); if (loggedUserId != null) message.setLong("loggedUserId", loggedUserId); sendMessage(session, message); } catch (JMSException e) { throw new EventException(e); } catch (NamingException e) { throw new EventException(e); } } }
/** * @param dataFile the byte data * @param entryType created, modified or deleted file * @param ID filename * @param session * @return Message object * @throws JMSException */ protected Message createByteArrayMessage( byte[] fileByteArray, String ID, String checksum, String domain, String projectName, String entryType, String dateTime, Session session) throws JMSException, XMLStreamException { /** Can replace this with XML string for parameters: entryType, ID and dateTime */ MapMessage message; message = session.createMapMessage(); String msgParam = createXMLParameter(ID, checksum, entryType, projectName, dateTime, domain, ""); message.setBytes("dataFile", fileByteArray); message.setString("msgParamXML", msgParam); // message.setString("checksum", msgParam); // message.setString("entryType", entryType); // message.setString("entryID", ID); return message; }
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; }
/** * @param fileURL the url of the file uploaded to fedora * @param ID * @param entryType * @param dateTime * @param session * @return * @throws JMSException * @throws XMLStreamException */ protected Message createNewExperimentMessage(String experimentXMLString) throws JMSException, XMLStreamException { MapMessage message = session.createMapMessage(); message.setString("msgParamXML", experimentXMLString); return message; }
/** * Set * * @param name The name * @param value The value * @throws JMSException Thrown if an error occurs */ @Override public void setString(final String name, final String value) throws JMSException { if (ActiveMQRAMapMessage.trace) { ActiveMQRALogger.LOGGER.trace("setString(" + name + ", " + value + ")"); } ((MapMessage) message).setString(name, value); }
@Override public void widgetSelected(SelectionEvent ev) { SendMapMessage sender = new SendMapMessage(); try { sender.startSender(); MapMessage message = sender.getSessionMessageObject(); PropertyList properties = messageTable.getPropertyList(); Vector<Property> propertyList = properties.getProperties(); ListIterator<Property> it = propertyList.listIterator(); while (it.hasNext()) { Property p = (Property) it.next(); message.setString(p.getProperty(), p.getValue()); } int count; try { count = Integer.parseInt(_countField.getText()); } catch (NumberFormatException e) { count = 1; } if (count == 1) { message.setString("EVENTTIME", (_jmsDateFormat.format(Calendar.getInstance().getTime()))); sender.sendMessage(_topicField.getText()); } else { for (int i = 0; i < count; i++) { String name = message.getString("NAME"); String[] nameParts = name.split("_"); name = nameParts[0] + "_" + i; message.setString("NAME", name); message.setString( "EVENTTIME", (_jmsDateFormat.format(Calendar.getInstance().getTime()))); sender.sendMessage(_topicField.getText()); } } } catch (Exception e) { MessageDialog.openError(null, "JMS Sender", "Error sending JMS message: " + e.getMessage()); } finally { try { sender.stopSender(); } catch (Exception e) { e.printStackTrace(); } } }
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; }
public void sendMessage(final Map<String, Serializable> properties, final String bodyId) throws JMSException { final MapMessage message = session.createMapMessage(); for (final Map.Entry<String, Serializable> property : properties.entrySet()) { message.setObjectProperty(property.getKey(), property.getValue()); } message.setString("body-id", bodyId); message.setJMSExpiration(System.currentTimeMillis() + timeout); producer.send(message); }
public boolean send(@NotNull Value value, @Optional JMSQueue replyTo) throws JMSException { Message message = null; if (value.isArray()) { message = _session.createMapMessage(); ArrayValue array = (ArrayValue) value; Set<Map.Entry<Value, Value>> entrySet = array.entrySet(); for (Map.Entry<Value, Value> entry : entrySet) { if (entry.getValue() instanceof BinaryValue) { byte[] bytes = ((BinaryValue) entry.getValue()).toBytes(); ((MapMessage) message).setBytes(entry.getKey().toString(), bytes); } else { // every primitive except for bytes can be translated from a string ((MapMessage) message).setString(entry.getKey().toString(), entry.getValue().toString()); } } } else if (value instanceof BinaryValue) { message = _session.createBytesMessage(); byte[] bytes = ((BinaryValue) value).toBytes(); ((BytesMessage) message).writeBytes(bytes); } else if (value.isLongConvertible()) { message = _session.createStreamMessage(); ((StreamMessage) message).writeLong(value.toLong()); } else if (value.isDoubleConvertible()) { message = _session.createStreamMessage(); ((StreamMessage) message).writeDouble(value.toDouble()); } else if (value.toJavaObject() instanceof String) { message = _session.createTextMessage(); ((TextMessage) message).setText(value.toString()); } else if (value.toJavaObject() instanceof Serializable) { message = _session.createObjectMessage(); ((ObjectMessage) message).setObject((Serializable) value.toJavaObject()); } else { return false; } if (replyTo != null) message.setJMSReplyTo(replyTo._destination); _producer.send(message); return true; }
@org.junit.Ignore public void testSendMapToQueue() throws Exception { final TestRunner runner = TestRunners.newTestRunner(GetJMSQueue.class); runner.setProperty(JmsProperties.JMS_PROVIDER, JmsProperties.ACTIVEMQ_PROVIDER); runner.setProperty(JmsProperties.URL, "tcp://localhost:61616"); runner.setProperty(JmsProperties.DESTINATION_TYPE, JmsProperties.DESTINATION_TYPE_QUEUE); runner.setProperty(JmsProperties.DESTINATION_NAME, "queue.testing"); runner.setProperty(JmsProperties.ACKNOWLEDGEMENT_MODE, JmsProperties.ACK_MODE_AUTO); WrappedMessageProducer wrappedProducer = JmsFactory.createMessageProducer(runner.getProcessContext(), true); final Session jmsSession = wrappedProducer.getSession(); final MessageProducer producer = wrappedProducer.getProducer(); final MapMessage message = jmsSession.createMapMessage(); message.setString("foo!", "bar"); message.setString("bacon", "meat"); producer.send(message); jmsSession.commit(); producer.close(); jmsSession.close(); }
public static void sendMessage() { Connection topicConnection = null; Session session = null; MapMessage message = null; MessageProducer producer = null; try { topicConnection = topicFactory.createConnection(); session = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer(topic); message = session.createMapMessage(); message.setString("lastname", "Smith"); message.setString("firstname", "John"); message.setString("id", "0100"); producer.send(message); System.out.println("sent a message"); } catch (Exception e) { log.log(Level.SEVERE, "Topic client exception: ", e); } }
/** * @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; }
/** * Create message initialized with basic alarm & application info * * @param text TEXT property * @return MapMessage * @throws Exception on error. */ private MapMessage createMapMessage(final String text) throws Exception { final MapMessage map = createMapMessage(); map.setString(JMSLogMessage.TYPE, JMSAlarmMessage.TYPE_ALARM); map.setString(JMSAlarmMessage.CONFIG, model.getConfigurationName()); map.setString(JMSLogMessage.TEXT, text); map.setString(JMSLogMessage.APPLICATION_ID, APPLICATION); map.setString(JMSLogMessage.HOST, host); User loggedUser = SecurityFacade.getInstance().getCurrentUser(); if (loggedUser == null) // if no user logged in... user = System.getProperty("user.name"); // $NON-NLS-1$ else user = loggedUser.getUsername(); map.setString(JMSLogMessage.USER, user); return map; }
@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; }
protected Message createStockMessage(String stock, Session session) throws JMSException { Double value = LAST_PRICES.get(stock); if (value == null) { value = new Double(Math.random() * 100); } // lets mutate the value by some percentage double oldPrice = value.doubleValue(); value = new Double(mutatePrice(oldPrice)); LAST_PRICES.put(stock, value); double price = value.doubleValue(); double offer = price * 1.001; boolean up = (price > oldPrice); MapMessage message = session.createMapMessage(); message.setString("stock", stock); message.setDouble("price", price); message.setDouble("offer", offer); message.setBoolean("up", up); return message; }
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()); } }