org.apache.activemq.command.Message.copy()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(13.3k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中org.apache.activemq.command.Message.copy()方法的一些代码示例,展示了Message.copy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.copy()方法的具体详情如下:
包路径:org.apache.activemq.command.Message
类名称:Message
方法名:copy

Message.copy介绍

暂无

代码示例

代码示例来源:origin: apache/activemq

protected void copy(ActiveMQMessage copy) {
  super.copy(copy);
  copy.acknowledgeCallback = acknowledgeCallback;
}

代码示例来源:origin: apache/activemq

private Message copy(Message original, ActiveMQDestination target) {
  Message msg = original.copy();
  if (setOriginalDestination) {
    msg.setDestination(target);
    msg.setOriginalDestination(original.getDestination());
  }
  return msg;
}

代码示例来源:origin: apache/activemq

@Override
public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws Exception {
  if (isLogAll() || isLogProducerEvents()) {
    logSend(messageSend.copy());
  }
  super.send(producerExchange, messageSend);
}

代码示例来源:origin: apache/activemq

/**
 * Sends a message to the given destination which may be a wildcard
 *
 * @param context broker context
 * @param message message to send
 * @param destination possibly wildcard destination to send the message to
 * @throws Exception on error
 */
protected void send(ProducerBrokerExchange context, Message message, ActiveMQDestination destination) throws Exception {
  Broker broker = context.getConnectionContext().getBroker();
  Set<Destination> destinations = broker.getDestinations(destination);
  for (Destination dest : destinations) {
    dest.send(context, message.copy());
  }
}

代码示例来源:origin: apache/activemq

private void doForward(ProducerBrokerExchange context, Message message, Broker regionBroker, ActiveMQDestination destination) throws Exception {
    Message forwardedMessage = message.copy();
    forwardedMessage.setMemoryUsage(null);

    forwardedMessage.setOriginalDestination( message.getDestination() );
    forwardedMessage.setDestination(destination);

    // Send it back through the region broker for routing.
    context.setMutable(true);
    regionBroker.send(context, forwardedMessage);
  }
}

代码示例来源:origin: apache/activemq

public boolean add(ConnectionContext context, MessageReference node) throws Exception {
  final Message message = node.getMessage();
  final Object retainValue = message.getProperty(RETAIN_PROPERTY);
  // retain property set to true
  final boolean retain = retainValue != null && Boolean.parseBoolean(retainValue.toString());
  if (retain) {
    if (message.getContent().getLength() > 0) {
      // non zero length message content
      retainedMessage = message.copy();
      retainedMessage.getMessage().removeProperty(RETAIN_PROPERTY);
      retainedMessage.getMessage().setProperty(RETAINED_PROPERTY, true);
    } else {
      // clear retained message
      retainedMessage = null;
    }
    // TODO should we remove the publisher's retain property??
    node.getMessage().removeProperty(RETAIN_PROPERTY);
  }
  return wrapped == null ? true : wrapped.add(context, node);
}

代码示例来源:origin: apache/activemq

public void send(ProducerBrokerExchange context, Message message) throws Exception {
    message.setDestination(mirrorDestination.getActiveMQDestination());
    mirrorDestination.send(context, message);
    if (isCopyMessage()) {
      message = message.copy();
    }
    message.setDestination(destination.getActiveMQDestination());
    message.setMemoryUsage(null); // set this to null so that it will use the queue memoryUsage instance instead of the topic.
    super.send(context, message);
  }
};

代码示例来源:origin: apache/activemq

@Override
public Response processMessageDispatch(MessageDispatch md) throws Exception {
  waitForTransportInterruptionProcessingToComplete();
  ActiveMQDispatcher dispatcher = dispatchers.get(md.getConsumerId());
  if (dispatcher != null) {
    // Copy in case a embedded broker is dispatching via
    // vm://
    // md.getMessage() == null to signal end of queue
    // browse.
    Message msg = md.getMessage();
    if (msg != null) {
      msg = msg.copy();
      msg.setReadOnlyBody(true);
      msg.setReadOnlyProperties(true);
      msg.setRedeliveryCounter(md.getRedeliveryCounter());
      msg.setConnection(ActiveMQConnection.this);
      msg.setMemoryUsage(null);
      md.setMessage(msg);
    }
    dispatcher.dispatch(md);
  } else {
    LOG.debug("{} no dispatcher for {} in {}", this, md, dispatchers);
  }
  return null;
}

代码示例来源:origin: apache/activemq

/**
 * 
 */
public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
  ActiveMQDestination destination = message.getDestination();
  if (destination.isComposite()) {
    ActiveMQDestination[] destinations = destination.getCompositeDestinations();
    for (int i = 0; i < destinations.length; i++) {
      if (i != 0) {
        message = message.copy();
        message.setMemoryUsage(null);
      }
      message.setOriginalDestination(destination);
      message.setDestination(destinations[i]);
      next.send(producerExchange, message);
    }
  } else {
    next.send(producerExchange, message);
  }
}

代码示例来源:origin: apache/activemq

private void doSchedule(Message messageSend, Object cronValue, Object periodValue, Object delayValue) throws Exception {
  long delay = 0;
  long period = 0;
  int repeat = 0;
  String cronEntry = "";
  // clear transaction context
  Message msg = messageSend.copy();
  msg.setTransactionId(null);
  org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(msg);
  if (cronValue != null) {
    cronEntry = cronValue.toString();
  }
  if (periodValue != null) {
    period = (Long) TypeConversionSupport.convert(periodValue, Long.class);
  }
  if (delayValue != null) {
    delay = (Long) TypeConversionSupport.convert(delayValue, Long.class);
  }
  Object repeatValue = msg.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
  if (repeatValue != null) {
    repeat = (Integer) TypeConversionSupport.convert(repeatValue, Integer.class);
  }
  //job id should be unique for every job (Same format as MessageId)
  MessageId jobId = new MessageId(messageSend.getMessageId().getProducerId(), longGenerator.getNextSequenceId());
  getInternalScheduler().schedule(jobId.toString(),
      new ByteSequence(packet.data, packet.offset, packet.length), cronEntry, delay, period, repeat);
}

代码示例来源:origin: apache/activemq

@Override
public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference,
                   Subscription subscription, Throwable poisonCause) {
  boolean wasDLQd = super.sendToDeadLetterQueue(context, messageReference, subscription, poisonCause);
  if (wasDLQd) {
    try {
      if (!messageReference.isAdvisory()) {
        BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination();
        ActiveMQTopic topic = AdvisorySupport.getMessageDLQdAdvisoryTopic(baseDestination.getActiveMQDestination());
        Message payload = messageReference.getMessage().copy();
        if (!baseDestination.isIncludeBodyForAdvisory()) {
          payload.clearBody();
        }
        fireAdvisory(context, topic, payload);
      }
    } catch (Exception e) {
      handleFireFailure("add to DLQ", e);
    }
  }
  return wasDLQd;
}

代码示例来源:origin: apache/activemq

private void scheduleRedelivery(ConnectionContext context, MessageReference messageReference, long delay, int redeliveryCount) throws Exception {
  if (LOG.isTraceEnabled()) {
    Destination regionDestination = (Destination) messageReference.getRegionDestination();
    LOG.trace("redelivery #{} of: {} with delay: {}, dest: {}", new Object[]{
        redeliveryCount, messageReference.getMessageId(), delay, regionDestination.getActiveMQDestination()
    });
  }
  final Message old = messageReference.getMessage();
  Message message = old.copy();
  message.setTransactionId(null);
  message.setMemoryUsage(null);
  message.removeProperty(ScheduledMessage.AMQ_SCHEDULED_ID);
  message.setProperty(REDELIVERY_DELAY, delay);
  message.setProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
  message.setRedeliveryCounter(redeliveryCount);
  boolean originalFlowControl = context.isProducerFlowControl();
  try {
    context.setProducerFlowControl(false);
    ProducerInfo info = new ProducerInfo();
    ProducerState state = new ProducerState(info);
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    producerExchange.setProducerState(state);
    producerExchange.setMutable(true);
    producerExchange.setConnectionContext(context);
    context.getBroker().send(producerExchange, message);
  } finally {
    context.setProducerFlowControl(originalFlowControl);
  }
}

代码示例来源:origin: apache/activemq

protected Message configureMessage(MessageDispatch md) throws IOException {
  Message message = md.getMessage().copy();
  // Update the packet to show where it came from.
  message.setBrokerPath(appendToBrokerPath(message.getBrokerPath(), localBrokerPath));
  message.setProducerId(producerInfo.getProducerId());
  message.setDestination(md.getDestination());
  message.setMemoryUsage(null);
  if (message.getOriginalTransactionId() == null) {
    message.setOriginalTransactionId(message.getTransactionId());
  }
  message.setTransactionId(null);
  if (configuration.isUseCompression()) {
    message.compress();
  }
  return message;
}

代码示例来源:origin: apache/activemq

@Override
public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) {
  super.messageExpired(context, messageReference, subscription);
  try {
    if (!messageReference.isAdvisory()) {
      BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination();
      ActiveMQTopic topic = AdvisorySupport.getExpiredMessageTopic(baseDestination.getActiveMQDestination());
      Message payload = messageReference.getMessage().copy();
      if (!baseDestination.isIncludeBodyForAdvisory()) {
        payload.clearBody();
      }
      ActiveMQMessage advisoryMessage = new ActiveMQMessage();
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
      fireAdvisory(context, topic, payload, null, advisoryMessage);
    }
  } catch (Exception e) {
    handleFireFailure("expired", e);
  }
}

代码示例来源:origin: apache/activemq

final Message copy = message.copy();
copy.setOriginalDestination(message.getDestination());
copy.setDestination(newDestination);

代码示例来源:origin: apache/activemq

@Override
public void messageConsumed(ConnectionContext context, MessageReference messageReference) {
  super.messageConsumed(context, messageReference);
  try {
    if (!messageReference.isAdvisory()) {
      BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination();
      ActiveMQTopic topic = AdvisorySupport.getMessageConsumedAdvisoryTopic(baseDestination.getActiveMQDestination());
      Message payload = messageReference.getMessage().copy();
      if (!baseDestination.isIncludeBodyForAdvisory()) {
        payload.clearBody();
      }
      ActiveMQMessage advisoryMessage = new ActiveMQMessage();
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_DESTINATION, baseDestination.getActiveMQDestination().getQualifiedName());
      fireAdvisory(context, topic, payload, null, advisoryMessage);
    }
  } catch (Exception e) {
    handleFireFailure("consumed", e);
  }
}

代码示例来源:origin: apache/activemq

@Override
public void messageDelivered(ConnectionContext context, MessageReference messageReference) {
  super.messageDelivered(context, messageReference);
  try {
    if (!messageReference.isAdvisory()) {
      BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination();
      ActiveMQTopic topic = AdvisorySupport.getMessageDeliveredAdvisoryTopic(baseDestination.getActiveMQDestination());
      Message payload = messageReference.getMessage().copy();
      if (!baseDestination.isIncludeBodyForAdvisory()) {
        payload.clearBody();
      }
      ActiveMQMessage advisoryMessage = new ActiveMQMessage();
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_DESTINATION, baseDestination.getActiveMQDestination().getQualifiedName());
      fireAdvisory(context, topic, payload, null, advisoryMessage);
    }
  } catch (Exception e) {
    handleFireFailure("delivered", e);
  }
}

代码示例来源:origin: apache/activemq

public static void doResend(final ConnectionContext context, Message originalMessage, ActiveMQDestination deadLetterDestination, boolean copy) throws Exception {
  Message message = copy ? originalMessage.copy() : originalMessage;
  message.setOriginalDestination(message.getDestination());
  message.setOriginalTransactionId(message.getTransactionId());
  message.setDestination(deadLetterDestination);
  message.setTransactionId(null);
  message.setMemoryUsage(null);
  message.setRedeliveryCounter(0);
  message.getMessageId().setDataLocator(null);
  boolean originalFlowControl = context.isProducerFlowControl();
  try {
    context.setProducerFlowControl(false);
    ProducerInfo info = new ProducerInfo();
    ProducerState state = new ProducerState(info);
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    producerExchange.setProducerState(state);
    producerExchange.setMutable(true);
    producerExchange.setConnectionContext(context);
    context.getBroker().send(producerExchange, message);
  } finally {
    context.setProducerFlowControl(originalFlowControl);
  }
}

代码示例来源:origin: apache/activemq

@Override
public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
  super.messageDiscarded(context, sub, messageReference);
  try {
    if (!messageReference.isAdvisory()) {
      BaseDestination baseDestination = (BaseDestination) messageReference.getMessage().getRegionDestination();
      ActiveMQTopic topic = AdvisorySupport.getMessageDiscardedAdvisoryTopic(baseDestination.getActiveMQDestination());
      Message payload = messageReference.getMessage().copy();
      if (!baseDestination.isIncludeBodyForAdvisory()) {
        payload.clearBody();
      }
      ActiveMQMessage advisoryMessage = new ActiveMQMessage();
      if (sub instanceof TopicSubscription) {
        advisoryMessage.setIntProperty(AdvisorySupport.MSG_PROPERTY_DISCARDED_COUNT, ((TopicSubscription) sub).discarded());
      }
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_MESSAGE_ID, payload.getMessageId().toString());
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_CONSUMER_ID, sub.getConsumerInfo().getConsumerId().toString());
      advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_DESTINATION, baseDestination.getActiveMQDestination().getQualifiedName());
      fireAdvisory(context, topic, payload, null, advisoryMessage);
    }
  } catch (Exception e) {
    handleFireFailure("discarded", e);
  }
}

代码示例来源:origin: apache/activemq

Message message = msg.copy();

相关文章

Message类方法