Esempio n. 1
0
 @Override
 public int compareTo(Exchange that) {
   if (this == that) {
     return 0;
   }
   int answer = Objects.compare(this.id, that.id);
   if (answer == 0) {
     // same exchange id, so sort by uuid if given
     Long uuid1 = in != null ? in.getUuid() : null;
     Long uuid2 = that.in != null ? that.in.getUuid() : null;
     if (uuid1 != null && uuid2 != null) {
       answer = uuid1.compareTo(uuid2);
     }
   }
   // sort by exchange index
   if (answer == 0) {
     answer = Objects.compare(this.in.getExchangeIndex(), that.in.getExchangeIndex());
   }
   // and then timestamp
   if (answer == 0) {
     answer = Objects.compare(this.in.getTimestamp(), that.in.getTimestamp());
   }
   return answer;
 }
  public void dropMessage(IMessage message) {
    Map<String, Object> headers = message.getHeaders();
    Map<String, Object> cleanHeaders = new HashMap<String, Object>();
    Set<Entry<String, Object>> entrySet = headers.entrySet();
    for (Entry<String, Object> entry : entrySet) {
      String key = entry.getKey();
      Object value = entry.getValue();
      if (value != null && !ignoreSendHeaders.contains(key)) {
        if (Objects.equal("JMSReplyTo", key)) {
          value = JmsTypeConverters.toDestination(value);
        } else if (Objects.equal("JMSExpiration", key)) {
          value = JmsTypeConverters.toTimestamp(value);
        } else if (Objects.equal("JMSTimestamp", key)) {
          value = JmsTypeConverters.toTimestamp(value);
        } else if (Objects.equal("JMSDeliveryMode", key)) {
          value = JmsTypeConverters.toDeliveryMode(value);
        } else if (Objects.equal("JMSRedelivered", key)) {
          value = JmsTypeConverters.toBoolean(value);
        } else if (Objects.equal("JMSPriority", key)) {
          value = JmsTypeConverters.toInteger(value);
        }

        if (value != null) {
          cleanHeaders.put(key, value);
        }
      }
    }

    String body = Strings.getOrElse(message.getBody());

    try {
      // TODO store username/pwd on a queue basis?
      String userName = getBrokerNode().getUserName();
      String password = getBrokerNode().getPassword();
      if (userName != null && password != null) {
        destination.sendTextMessage(cleanHeaders, body, userName, password);
      } else {
        destination.sendTextMessage(cleanHeaders, body);
      }
    } catch (Exception e) {
      FabricPlugin.showUserError(
          "Send message to " + this + " failed", "Could not send message to " + this, e);
    }
  }