예제 #1
0
  /**
   * @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;
  }
예제 #2
0
  @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);
      }
    }
  }
예제 #3
0
 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;
 }
 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;
 }
예제 #5
0
파일: JmsBinding.java 프로젝트: mnki/camel
 /**
  * Create the {@link Message}
  *
  * @return jmsMessage or null if the mapping was not successfully
  */
 protected Message createJmsMessageForType(
     Exchange exchange,
     Object body,
     Map<String, Object> headers,
     Session session,
     CamelContext context,
     JmsMessageType type)
     throws JMSException {
   switch (type) {
     case Text:
       {
         TextMessage message = session.createTextMessage();
         if (body != null) {
           String payload = context.getTypeConverter().convertTo(String.class, exchange, body);
           message.setText(payload);
         }
         return message;
       }
     case Bytes:
       {
         BytesMessage message = session.createBytesMessage();
         if (body != null) {
           byte[] payload = context.getTypeConverter().convertTo(byte[].class, exchange, body);
           message.writeBytes(payload);
         }
         return message;
       }
     case Map:
       {
         MapMessage message = session.createMapMessage();
         if (body != null) {
           Map<?, ?> payload = context.getTypeConverter().convertTo(Map.class, exchange, body);
           populateMapMessage(message, payload, context);
         }
         return message;
       }
     case Object:
       ObjectMessage message = session.createObjectMessage();
       if (body != null) {
         try {
           Serializable payload =
               context.getTypeConverter().mandatoryConvertTo(Serializable.class, exchange, body);
           message.setObject(payload);
         } catch (NoTypeConversionAvailableException e) {
           // cannot convert to serializable then thrown an exception to avoid sending a null
           // message
           JMSException cause = new MessageFormatException(e.getMessage());
           cause.initCause(e);
           throw cause;
         }
       }
       return message;
     default:
       break;
   }
   return null;
 }
  public void execute(Tuple input) {
    NewsSentiment newsData = (NewsSentiment) input.getValue(0);
    try {
      MapMessage message = session.createMapMessage();
      message.setBytes("key", newsData.toByteArray());
      producer.send(message);

    } catch (JMSException e) {
      e.printStackTrace();
    }
  }
예제 #7
0
  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);
  }
예제 #8
0
파일: JMSQueue.java 프로젝트: dlitz/resin
  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;
  }
예제 #9
0
 private Message createMessage(Session session, int messageType) throws JMSException {
   switch (messageType) {
     case MessageImpl.TEXT_MESSAGE:
       return session.createTextMessage();
     case MessageImpl.BYTES_MESSAGE:
       return session.createBytesMessage();
     case MessageImpl.MAP_MESSAGE:
       return session.createMapMessage();
     case MessageImpl.STREAM_MESSAGE:
       return session.createStreamMessage();
     case MessageImpl.OBJECT_MESSAGE:
       return session.createObjectMessage();
     default:
       return session.createTextMessage();
   }
 }
예제 #10
0
 /**
  * Each message will be divided into groups and create the map message
  *
  * @param producer Used for sending messages to a destination
  * @param session Used to produce the messages to be sent
  * @param messagesList List of messages to be sent individual message event data should be in
  *     "attributeName(attributeType):attributeValue" format
  */
 public static void publishMapMessage(
     MessageProducer producer, Session session, List<String> messagesList)
     throws IOException, JMSException {
   String regexPattern = "(.*)\\((.*)\\):(.*)";
   Pattern pattern = Pattern.compile(regexPattern);
   for (String message : messagesList) {
     MapMessage mapMessage = session.createMapMessage();
     for (String line : message.split("\\n")) {
       if (line != null && !line.equalsIgnoreCase("")) {
         Matcher matcher = pattern.matcher(line);
         if (matcher.find()) {
           mapMessage.setObject(
               matcher.group(1), parseAttributeValue(matcher.group(2), matcher.group(3)));
         }
       }
     }
     producer.send(mapMessage);
   }
 }
예제 #11
0
  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;
  }
예제 #12
0
  @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();
  }
  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 Message createMessage(Session session, Class messageClazz) throws JMSException {
    if (session == null) {
      throw new JMSException("session cannot be null");
    }
    if (Message.class.isAssignableFrom(messageClazz)) {
      throw new JMSException("cannot create message of type: " + messageClazz.getName());
    }

    if (TextMessage.class.equals(messageClazz)) {
      return session.createTextMessage();
    } else if (StreamMessage.class.equals(messageClazz)) {
      return session.createStreamMessage();
    } else if (MapMessage.class.equals(messageClazz)) {
      return session.createMapMessage();
    } else if (ObjectMessage.class.equals(messageClazz)) {
      return session.createObjectMessage();
    } else if (BytesMessage.class.equals(messageClazz)) {
      return session.createBytesMessage();
    } else if (Message.class.equals(messageClazz)) {
      return session.createMessage();
    } else {
      throw new JMSException("cannot create message of type: " + messageClazz.getName());
    }
  }
예제 #15
0
  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);
    }
  }