public void onMessage(Message message) { if (message instanceof ActiveMQMessage) { ActiveMQMessage activeMessage = (ActiveMQMessage) message; Object command = activeMessage.getDataStructure(); if (command instanceof DestinationInfo) { DestinationInfo destinationInfo = (DestinationInfo) command; DestinationEvent event = new DestinationEvent(this, destinationInfo); fireDestinationEvent(event); } else { LOG.warn("Unknown dataStructure: " + command); } } else { LOG.warn("Unknown message type: " + message + ". Message ignored"); } }
protected void dispatchInitialMessage(Message message, Destination regionDestination, ConnectionContext context, SubscriptionRecovery sub) { try { ActiveMQMessage activeMessage = ActiveMQMessageTransformation.transformMessage(message, null); ActiveMQDestination destination = activeMessage.getDestination(); if (destination == null) { destination = sub.getActiveMQDestination(); activeMessage.setDestination(destination); } activeMessage.setRegionDestination(regionDestination); configure(activeMessage); sub.addRecoveredMessage(context, activeMessage); } catch (Throwable e) { LOG.warn("Failed to dispatch initial message: {} into subscription. Reason: ", message, e); } }
@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); } }
@Override public Message copy() { ActiveMQMessage copy = new ActiveMQMessage(); copy(copy); return copy; }
protected void configure(ActiveMQMessage msg) throws JMSException { long sequenceNumber = messageSequence.incrementAndGet(); msg.setMessageId(new MessageId(producerId, sequenceNumber)); msg.onSend(); msg.setProducerId(producerId); }
checkClosedOrFailed(); if (destination.isTemporary() && isDeleted(destination)) { throw new JMSException("Cannot publish to a deleted Destination: " + destination); msg.setJMSDestination(destination); msg.setJMSDeliveryMode(deliveryMode); long expiration = 0L; if (!isDisableTimeStampsByDefault()) { long timeStamp = System.currentTimeMillis(); msg.setJMSTimestamp(timeStamp); if (timeToLive > 0) { expiration = timeToLive + timeStamp; msg.setJMSExpiration(expiration); msg.setJMSPriority(priority); msg.setJMSRedelivered(false); msg.setMessageId(messageId); msg.onSend(); msg.setProducerId(msg.getMessageId().getProducerId());
if (msg.getJMSCorrelationID() != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSCorrelationID", msg.getJMSCorrelationID()); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSDeliveryMode", (msg.getJMSDeliveryMode() == DeliveryMode.PERSISTENT) ? "persistent" : "non-persistent"); if (msg.getJMSDestination() != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSDestination", ((ActiveMQDestination)msg.getJMSDestination()).getPhysicalName()); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSExpiration", Long.toString(msg.getJMSExpiration())); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSMessageID", msg.getJMSMessageID()); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSPriority", Integer.toString(msg.getJMSPriority())); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSRedelivered", Boolean.toString(msg.getJMSRedelivered())); if (msg.getJMSReplyTo() != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSReplyTo", ((ActiveMQDestination)msg.getJMSReplyTo()).getPhysicalName()); props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSTimestamp", Long.toString(msg.getJMSTimestamp())); if (msg.getJMSType() != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_HEADER_PREFIX + "JMSType", msg.getJMSType()); if (msg.getOriginalDestination() != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX + "OriginalDestination", msg.getOriginalDestination().getPhysicalName()); Enumeration e = msg.getPropertyNames(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); if (msg.getObjectProperty(name) != null) { props.put(AmqMessagesUtil.JMS_MESSAGE_CUSTOM_PREFIX + name, getDisplayString(msg.getObjectProperty(name)));
if (destination.isTemporary() && connection.isDeleted(destination)) { throw new InvalidDestinationException("Cannot publish to a deleted Destination: " + destination); msg.setDestination(destination); msg.setMessageId(new MessageId(producer.getProducerInfo().getProducerId(), sequenceNumber)); message.setJMSMessageID(msg.getMessageId().toString()); msg.setBrokerPath(null); msg.setTransactionId(txid); if (connection.isCopyMessageOnSend()) { msg = (ActiveMQMessage)msg.copy(); msg.setConnection(connection); msg.onSend(); msg.setProducerId(msg.getMessageId().getProducerId()); if (LOG.isTraceEnabled()) { LOG.trace(getSessionId() + " sending message: " + msg); if (onComplete==null && sendTimeout <= 0 && !msg.isResponseRequired() && !connection.isAlwaysSyncSend() && (!msg.isPersistent() || connection.isUseAsyncSend() || txid != null)) { this.connection.asyncSendPacket(msg); if (producerWindow != null) { int size = msg.getSize(); producerWindow.increaseUsage(size);
safeWaitUntilStarted(); MessageDispatch md = (MessageDispatch) command; serviceRemoteConsumerAdvisory(md.getMessage().getDataStructure()); ackAdvisory(md.getMessage()); } else if (command.isBrokerInfo()) { futureRemoteBrokerInfo.set((BrokerInfo) command); final ActiveMQMessage message = (ActiveMQMessage) command; if (NetworkBridgeFilter.isAdvisoryInterpretedByNetworkBridge(message)) { serviceRemoteConsumerAdvisory(message.getDataStructure()); ackAdvisory(message); } else { if (!isPermissableDestination(message.getDestination(), true)) { return; message.setProducerId(duplexInboundLocalProducerInfo.getProducerId()); if (message.isResponseRequired() || configuration.isAlwaysSyncSend()) { duplexInboundLocalBroker.asyncRequest(message, new ResponseCallback() { final int correlationId = message.getCommandId(); if (message.isResponseRequired() || configuration.isAlwaysSyncSend()) { Response reply = new Response(); reply.setCorrelationId(message.getCommandId()); remoteBroker.oneway(reply);
ActiveMQMessage m = (ActiveMQMessage)o; Map<String, Object> rc = super.getFields(o); rc.put("JMSCorrelationID", m.getJMSCorrelationID()); rc.put("JMSDestination", "" + m.getJMSDestination()); rc.put("JMSMessageID", m.getJMSMessageID()); rc.put("JMSReplyTo",toString(m.getJMSReplyTo())); rc.put("JMSType", m.getJMSType()); rc.put("JMSDeliveryMode", m.getJMSDeliveryMode() == DeliveryMode.PERSISTENT ? "PERSISTENT" : "NON-PERSISTENT"); rc.put("JMSExpiration", Long.valueOf(m.getJMSExpiration())); rc.put("JMSPriority", Integer.valueOf(m.getJMSPriority())); rc.put("JMSRedelivered", Boolean.valueOf(m.getJMSRedelivered())); rc.put("JMSTimestamp", new Date(m.getJMSTimestamp())); rc.put(CompositeDataConstants.JMSXGROUP_ID, m.getGroupID()); rc.put(CompositeDataConstants.JMSXGROUP_SEQ, m.getGroupSequence()); rc.put(CompositeDataConstants.JMSXUSER_ID, m.getUserID()); rc.put(CompositeDataConstants.BROKER_PATH, Arrays.toString(m.getBrokerPath())); rc.put(CompositeDataConstants.ORIGINAL_DESTINATION, toString(m.getOriginalDestination())); try { rc.put(CompositeDataConstants.PROPERTIES, "" + m.getProperties()); } catch (IOException e) { rc.put(CompositeDataConstants.PROPERTIES, "");
Destination toDestination = message.getJMSDestination(); if (toDestination == null || !(toDestination instanceof ActiveMQDestination)) { Rejected rejected = new Rejected(); message.setJMSDestination(getDestination()); message.setProducerId(getProducerId()); MessageId messageId = new MessageId(getProducerId(), messageIdGenerator.getNextSequenceId()); MessageId amqpMessageId = message.getMessageId(); if (amqpMessageId != null) { if (amqpMessageId.getTextView() != null) { messageId.setTextView(amqpMessageId.getTextView()); } else { messageId.setTextView(amqpMessageId.toString()); message.setMessageId(messageId); message.getMessageId(), getProducerId() + ":" + messageId.getProducerSequenceId()); TransactionId txId = new LocalTransactionId(session.getConnection().getConnectionId(), toLong(txState.getTxnId())); session.enlist(txId); message.setTransactionId(txId); message.onSend();
while ((messageDispatch = executor.dequeueNoWait()) != null) { final MessageDispatch md = messageDispatch; final ActiveMQMessage message = (ActiveMQMessage)md.getMessage(); if (message.isExpired()) { earlyAck = new MessageAck(md, MessageAck.EXPIRED_ACK_TYPE, 1); earlyAck.setFirstMessageId(message.getMessageId()); } else if (connection.isDuplicate(ActiveMQSession.this, message)) { LOG.debug("{} got duplicate: {}", this, message.getMessageId()); earlyAck = new MessageAck(md, MessageAck.POSION_ACK_TYPE, 1); earlyAck.setFirstMessageId(md.getMessage().getMessageId()); earlyAck.setPoisonCause(new Throwable("Duplicate delivery to " + this)); message.setAcknowledgeCallback(new Callback() { @Override public void execute() throws Exception { md.setDeliverySequenceId(getNextDeliveryId()); lastDeliveredSequenceId = message.getMessageId().getBrokerSequenceId(); ack.setFirstMessageId(md.getMessage().getMessageId()); doStartTransaction(); ack.setTransactionId(getTransactionContext().getTransactionId()); LOG.trace("{} onMessage({})", this, message.getMessageId()); messageListener.onMessage(message); LOG.error("{} error dispatching message: {} ", this, message.getMessageId(), e);
@Override public void set(Message message, Object value) throws MessageFormatException { String rc = (String) TypeConversionSupport.convert(value, String.class); if (rc == null) { throw new MessageFormatException("Property JMSType cannot be set from a " + value.getClass().getName() + "."); } ((ActiveMQMessage) message).setJMSType(rc); } });
public void fireAdvisory(ConnectionContext context, ActiveMQTopic topic, Command command, ConsumerId targetConsumerId, ActiveMQMessage advisoryMessage) throws Exception { advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_NAME, getBrokerName()); String id = getBrokerId() != null ? getBrokerId().getValue() : "NOT_SET"; advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id); url = getBrokerService().getDefaultSocketURIString(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_URL, url); advisoryMessage.setDataStructure(command); advisoryMessage.setPersistent(false); advisoryMessage.setType(AdvisorySupport.ADIVSORY_MESSAGE_TYPE); advisoryMessage.setMessageId(new MessageId(advisoryProducerId, messageIdGenerator.getNextSequenceId())); advisoryMessage.setTargetConsumerId(targetConsumerId); advisoryMessage.setDestination(topic); advisoryMessage.setResponseRequired(false); advisoryMessage.setProducerId(advisoryProducerId); boolean originalFlowControl = context.isProducerFlowControl(); final ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
if (message.propertyExists(QOS_PROPERTY_NAME)) { int ordinal = message.getIntProperty(QOS_PROPERTY_NAME); qoS = QoS.values()[ordinal]; qoS = message.isPersistent() ? QoS.AT_MOST_ONCE : QoS.AT_LEAST_ONCE; if (message.getBooleanProperty(RetainedMessageSubscriptionRecoveryPolicy.RETAINED_PROPERTY)) { result.retain(true); topicName = mqttTopicMap.get(message.getJMSDestination()); if (topicName == null) { String amqTopicName = findSubscriptionStrategy().onSend(message.getDestination()); topicName = MQTTProtocolSupport.convertActiveMQToMQTT(amqTopicName); mqttTopicMap.put(message.getJMSDestination(), topicName); if (message.getDataStructureType() == ActiveMQTextMessage.DATA_STRUCTURE_TYPE) { ActiveMQTextMessage msg = (ActiveMQTextMessage) message.copy(); msg.setReadOnlyBody(true); String messageText = msg.getText(); } else if (message.getDataStructureType() == ActiveMQBytesMessage.DATA_STRUCTURE_TYPE) { ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message.copy(); msg.setReadOnlyBody(true); byte[] data = new byte[(int) msg.getBodyLength()]; msg.readBytes(data); result.payload(new Buffer(data)); } else if (message.getDataStructureType() == ActiveMQMapMessage.DATA_STRUCTURE_TYPE) { ActiveMQMapMessage msg = (ActiveMQMapMessage) message.copy(); msg.setReadOnlyBody(true);
if (message.getDataStructureType() == ActiveMQTextMessage.DATA_STRUCTURE_TYPE) { if (!message.isCompressed() && message.getContent() != null) { ByteSequence msgContent = message.getContent(); if (msgContent.getLength() > 4) { byte[] content = new byte[msgContent.getLength() - 4]; ActiveMQTextMessage msg = (ActiveMQTextMessage)message.copy(); String messageText = msg.getText(); if (messageText != null) { } else if (message.getDataStructureType() == ActiveMQBytesMessage.DATA_STRUCTURE_TYPE) { ActiveMQBytesMessage msg = (ActiveMQBytesMessage)message.copy(); msg.setReadOnlyBody(true); byte[] data = new byte[(int)msg.getBodyLength()];
private boolean isDestinationDLQ(Message message) { DeadLetterStrategy deadLetterStrategy; Message tmp; Destination regionDestination = (Destination) message.getRegionDestination(); if (message != null && regionDestination != null) { deadLetterStrategy = regionDestination.getDeadLetterStrategy(); if (deadLetterStrategy != null && message.getOriginalDestination() != null) { // Cheap copy, since we only need two fields tmp = new ActiveMQMessage(); tmp.setDestination(message.getOriginalDestination()); tmp.setRegionDestination(regionDestination); // Determine if we are headed for a DLQ ActiveMQDestination deadLetterDestination = deadLetterStrategy.getDeadLetterQueueFor(tmp, null); if (deadLetterDestination.equals(message.getDestination())) { return true; } } } return false; } }
public static void copyStandardHeadersFromFrameToMessage(ProtocolConverter converter, StompFrame command, ActiveMQMessage msg, FrameTranslator ft) throws ProtocolException, JMSException { final Map<String, String> headers = new HashMap<String, String>(command.getHeaders()); final String destination = headers.remove(Stomp.Headers.Send.DESTINATION); msg.setDestination(ft.convertDestination(converter, destination)); msg.setJMSCorrelationID(headers.remove(Stomp.Headers.Send.CORRELATION_ID)); msg.setJMSExpiration(Long.parseLong((String)o)); msg.setJMSPriority(Integer.parseInt((String)o)); } else { msg.setJMSPriority(javax.jms.Message.DEFAULT_PRIORITY); msg.setJMSType((String)o); msg.setJMSReplyTo(ft.convertDestination(converter, (String)o)); msg.setPersistent("true".equals(o)); msg.setProperties(headers);
@Override public void messageExpired(ConnectionContext context, MessageReference messageReference, Subscription subscription) { super.messageExpired(context, messageReference, subscription); try { if(!messageReference.isAdvisory()) { ActiveMQTopic topic = AdvisorySupport.getExpiredMessageTopic(messageReference.getMessage().getDestination()); Message payload = messageReference.getMessage().copy(); 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); } }
/** * Return the topic for the message's destination * * @param jmsMessage * @return * @throws JMSException */ public static String getJmsTopic(ActiveMQMessage jmsMessage) throws JMSException { String jmsTopic = null; if (jmsMessage.getDestination().isTopic()) { jmsTopic = ((Topic) jmsMessage.getJMSDestination()).getTopicName().substring(KapuaSecurityBrokerFilter.VT_TOPIC_PREFIX.length()); } else if (jmsMessage.getDestination().isQueue()) { jmsTopic = jmsMessage.getStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC); } else { logger.warn("jmsMessage destination is not a Topic or Queue: {}", jmsMessage.getDestination()); } return jmsTopic; }