Message msg = ref.getMessage().copy();
@Override protected Message beforeForward(final Message message, final SimpleString forwardingAddress) { // We make a copy of the message, then we strip out the unwanted routing id headers and leave // only // the one pertinent for the address node - this is important since different queues on different // nodes could have same queue ids // Note we must copy since same message may get routed to other nodes which require different headers Message messageCopy = message.copy(); if (logger.isTraceEnabled()) { logger.trace("Clustered bridge copied message " + message + " as " + messageCopy + " before delivery"); } // TODO - we can optimise this Set<SimpleString> propNames = new HashSet<>(messageCopy.getPropertyNames()); byte[] queueIds = message.getExtraBytesProperty(idsHeaderName); if (queueIds == null) { // Sanity check only ActiveMQServerLogger.LOGGER.noQueueIdDefined(message, messageCopy, idsHeaderName); throw new IllegalStateException("no queueIDs defined"); } for (SimpleString propName : propNames) { if (propName.startsWith(Message.HDR_ROUTE_TO_IDS)) { messageCopy.removeProperty(propName); } } messageCopy.putExtraBytesProperty(Message.HDR_ROUTE_TO_IDS, queueIds); messageCopy = super.beforeForward(messageCopy, forwardingAddress); return messageCopy; }
originalMessage.putStringProperty(Message.HDR_ROUTING_TYPE.toString(), routingTypeString); Message message = originalMessage.copy();
private Message makeCopy(final MessageReference ref, final boolean expiry, final boolean copyOriginalHeaders) throws Exception { if (ref == null) { ActiveMQServerLogger.LOGGER.nullRefMessage(); throw new ActiveMQNullRefException("Reference to message is null"); } Message message = ref.getMessage(); /* We copy the message and send that to the dla/expiry queue - this is because otherwise we may end up with a ref with the same message id in the queue more than once which would barf - this might happen if the same message had been expire from multiple subscriptions of a topic for example We set headers that hold the original message address, expiry time and original message id */ long newID = storageManager.generateID(); Message copy = message.copy(newID); if (copyOriginalHeaders) { copy.referenceOriginalMessage(message, ref.getQueue().getName().toString()); } copy.setExpiration(0); if (expiry) { copy.setAnnotation(Message.HDR_ACTUAL_EXPIRY_TIME, System.currentTimeMillis()); } copy.reencode(); return copy; }
Message message = messageRef.getMessage().copy();
Message copyRedistribute = message.copy(storageManager.generateID()); copyRedistribute.setAddress(originatingQueue.getAddress());
copy = message.copy(id);
/** * FIXME * Retained messages should be handled in the core API. There is currently no support for retained messages * at the time of writing. Instead we handle retained messages here. This method will create a new queue for * every address that is used to store retained messages. THere should only ever be one message in the retained * message queue. When a new subscription is created the queue should be browsed and the message copied onto * the subscription queue for the consumer. When a new retained message is received the message will be sent to * the retained queue and the previous retain message consumed to remove it from the queue. */ void handleRetainedMessage(Message message, String address, boolean reset, Transaction tx) throws Exception { SimpleString retainAddress = new SimpleString(MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration())); Queue queue = session.getServer().locateQueue(retainAddress); if (queue == null) { queue = session.getServer().createQueue(retainAddress, retainAddress, null, true, false); } try (LinkedListIterator<MessageReference> iterator = queue.iterator()) { synchronized (queue) { if (iterator.hasNext()) { MessageReference ref = iterator.next(); iterator.remove(); queue.acknowledge(tx, ref); } if (!reset) { sendToQueue(message.copy(session.getServer().getStorageManager().generateID()), queue, tx); } } } }
/** * FIXME * Retained messages should be handled in the core API. There is currently no support for retained messages * at the time of writing. Instead we handle retained messages here. This method will create a new queue for * every address that is used to store retained messages. THere should only ever be one message in the retained * message queue. When a new subscription is created the queue should be browsed and the message copied onto * the subscription queue for the consumer. When a new retained message is received the message will be sent to * the retained queue and the previous retain message consumed to remove it from the queue. */ void handleRetainedMessage(Message message, String address, boolean reset, Transaction tx) throws Exception { SimpleString retainAddress = new SimpleString(MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration())); Queue queue = session.getServer().locateQueue(retainAddress); if (queue == null) { queue = session.getServer().createQueue(retainAddress, retainAddress, null, true, false); } try (LinkedListIterator<MessageReference> iterator = queue.iterator()) { synchronized (queue) { if (iterator.hasNext()) { MessageReference ref = iterator.next(); iterator.remove(); queue.acknowledge(tx, ref); } if (!reset) { sendToQueue(message.copy(session.getServer().getStorageManager().generateID()), queue, tx); } } } }
final SimpleString address = SimpleString.toSimpleString(physicalName, coreMessageObjectPools.getAddressStringSimpleStringPool()); final org.apache.activemq.artemis.api.core.Message coreMsg = (i == actualDestinationsCount - 1) ? originalCoreMsg : originalCoreMsg.copy(); coreMsg.setAddress(address);
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception { // The address filter that matches all retained message queues. String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration()); BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress)); // Iterate over all matching retain queues and add the queue Transaction tx = session.getServerSession().newTransaction(); try { synchronized (queue) { for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) { Queue retainedQueue = session.getServer().locateQueue(retainedQueueName); try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) { if (i.hasNext()) { Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID()); sendToQueue(message, queue, tx); } } } } } catch (Throwable t) { tx.rollback(); throw t; } tx.commit(); }
void addRetainedMessagesToQueue(Queue queue, String address) throws Exception { // The address filter that matches all retained message queues. String retainAddress = MQTTUtil.convertMQTTAddressFilterToCoreRetain(address, session.getWildcardConfiguration()); BindingQueryResult bindingQueryResult = session.getServerSession().executeBindingQuery(new SimpleString(retainAddress)); // Iterate over all matching retain queues and add the queue Transaction tx = session.getServerSession().newTransaction(); try { synchronized (queue) { for (SimpleString retainedQueueName : bindingQueryResult.getQueueNames()) { Queue retainedQueue = session.getServer().locateQueue(retainedQueueName); try (LinkedListIterator<MessageReference> i = retainedQueue.iterator()) { if (i.hasNext()) { Message message = i.next().getMessage().copy(session.getServer().getStorageManager().generateID()); sendToQueue(message, queue, tx); } } } } } catch (Throwable t) { tx.rollback(); throw t; } tx.commit(); }