示例#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;
  }
  /**
   * Set
   *
   * @param name The name
   * @param value The value
   * @throws JMSException Thrown if an error occurs
   */
  @Override
  public void setBytes(final String name, final byte[] value) throws JMSException {
    if (ActiveMQRAMapMessage.trace) {
      ActiveMQRALogger.LOGGER.trace("setBytes(" + name + ", " + Arrays.toString(value) + ")");
    }

    ((MapMessage) message).setBytes(name, value);
  }
  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();
    }
  }
示例#4
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;
  }
 @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;
 }