/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
public void printMessageAttributes(ICoreMessage message) throws XMLStreamException { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_ID, Long.toString(message.getMessageID())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_PRIORITY, Byte.toString(message.getPriority())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_EXPIRATION, Long.toString(message.getExpiration())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TIMESTAMP, Long.toString(message.getTimestamp())); String prettyType = XmlDataExporterUtil.getMessagePrettyType(message.getType()); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TYPE, prettyType); if (message.getUserID() != null) { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_USER_ID, message.getUserID().toString()); } } }
@Override public StompFrame createMessageFrame(ICoreMessage serverMessage, ActiveMQBuffer bodyBuffer, StompSubscription subscription, int deliveryCount) throws Exception { StompFrame frame = super.createMessageFrame(serverMessage, bodyBuffer, subscription, deliveryCount); if (!subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { frame.addHeader(Stomp.Headers.Message.ACK, String.valueOf(serverMessage.getMessageID())); } return frame; }
public void printMessageAttributes(ICoreMessage message) throws XMLStreamException { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_ID, Long.toString(message.getMessageID())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_PRIORITY, Byte.toString(message.getPriority())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_EXPIRATION, Long.toString(message.getExpiration())); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TIMESTAMP, Long.toString(message.getTimestamp())); String prettyType = XmlDataExporterUtil.getMessagePrettyType(message.getType()); xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_TYPE, prettyType); if (message.getUserID() != null) { xmlWriter.writeAttribute(XmlDataConstants.MESSAGE_USER_ID, message.getUserID().toString()); } } }
@Override public StompFrame createMessageFrame(ICoreMessage serverMessage, ActiveMQBuffer bodyBuffer, StompSubscription subscription, int deliveryCount) throws Exception { StompFrame frame = super.createMessageFrame(serverMessage, bodyBuffer, subscription, deliveryCount); if (!subscription.getAck().equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) { frame.addHeader(Stomp.Headers.Message.ACK, String.valueOf(serverMessage.getMessageID())); } return frame; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * @return Returns the message in Map form, useful when encoding to JSON */ @Override default Map<String, Object> toMap() { Map map = toPropertyMap(); map.put("messageID", getMessageID()); Object userID = getUserID(); if (getUserID() != null) { map.put("userID", "ID:" + userID.toString()); } map.put("address", getAddress() == null ? "" : getAddress()); map.put("type", getType()); map.put("durable", isDurable()); map.put("expiration", getExpiration()); map.put("timestamp", getTimestamp()); map.put("priority", getPriority()); return map; }
/** * Since MQTT Subscriptions can over lap; a client may receive the same message twice. When this happens the client * returns a PubRec or PubAck with ID. But we need to know which consumer to ack, since we only have the ID to go on we * are not able to decide which consumer to ack. Instead we send MQTT messages with different IDs and store a reference * to original ID and consumer in the Session state. This way we can look up the consumer Id and the message Id from * the PubAck or PubRec message id. * */ protected void sendMessage(ICoreMessage message, ServerConsumer consumer, int deliveryCount) throws Exception { // This is to allow retries of PubRel. if (isManagementConsumer(consumer)) { sendPubRelMessage(message); } else { int qos = decideQoS(message, consumer); if (qos == 0) { sendServerMessage((int) message.getMessageID(), message, deliveryCount, qos); session.getServerSession().individualAcknowledge(consumer.getID(), message.getMessageID()); } else if (qos == 1 || qos == 2) { int mqttid = outboundStore.generateMqttId(message.getMessageID(), consumer.getID()); outboundStore.publish(mqttid, message.getMessageID(), consumer.getID()); sendServerMessage(mqttid, message, deliveryCount, qos); } else { // Client must have disconnected and it's Subscription QoS cleared consumer.individualCancel(message.getMessageID(), false); } } }
/** * Since MQTT Subscriptions can over lap; a client may receive the same message twice. When this happens the client * returns a PubRec or PubAck with ID. But we need to know which consumer to ack, since we only have the ID to go on we * are not able to decide which consumer to ack. Instead we send MQTT messages with different IDs and store a reference * to original ID and consumer in the Session state. This way we can look up the consumer Id and the message Id from * the PubAck or PubRec message id. * */ protected void sendMessage(ICoreMessage message, ServerConsumer consumer, int deliveryCount) throws Exception { // This is to allow retries of PubRel. if (isManagementConsumer(consumer)) { sendPubRelMessage(message); } else { int qos = decideQoS(message, consumer); if (qos == 0) { sendServerMessage((int) message.getMessageID(), message, deliveryCount, qos); session.getServerSession().individualAcknowledge(consumer.getID(), message.getMessageID()); } else if (qos == 1 || qos == 2) { int mqttid = outboundStore.generateMqttId(message.getMessageID(), consumer.getID()); outboundStore.publish(mqttid, message.getMessageID(), consumer.getID()); sendServerMessage(mqttid, message, deliveryCount, qos); } else { // Client must have disconnected and it's Subscription QoS cleared consumer.individualCancel(message.getMessageID(), false); } } }
private void sendServerMessage(int messageId, ICoreMessage message, int deliveryCount, int qos) { String address = MQTTUtil.convertCoreAddressFilterToMQTT(message.getAddress() == null ? "" : message.getAddress().toString(), session.getWildcardConfiguration()); boolean isRetain = message.getBooleanProperty(MQTT_MESSAGE_RETAIN_KEY); ByteBuf payload; switch (message.getType()) { case Message.TEXT_TYPE: try { SimpleString text = message.getDataBuffer().readNullableSimpleString(); byte[] stringPayload = text.toString().getBytes("UTF-8"); payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length); payload.writeBytes(stringPayload); break; } catch (UnsupportedEncodingException e) { log.warn("Unable to send message: " + message.getMessageID() + " Cause: " + e.getMessage(), e); } default: ActiveMQBuffer bodyBuffer = message.getDataBuffer(); payload = ByteBufAllocator.DEFAULT.buffer(bodyBuffer.writerIndex()); payload.writeBytes(bodyBuffer.byteBuf()); break; } session.getProtocolHandler().send(messageId, address, qos, isRetain, payload, deliveryCount); }
private void sendServerMessage(int messageId, ICoreMessage message, int deliveryCount, int qos) { String address = MQTTUtil.convertCoreAddressFilterToMQTT(message.getAddress() == null ? "" : message.getAddress().toString(), session.getWildcardConfiguration()); boolean isRetain = message.getBooleanProperty(MQTT_MESSAGE_RETAIN_KEY); ByteBuf payload; switch (message.getType()) { case Message.TEXT_TYPE: try { SimpleString text = message.getDataBuffer().readNullableSimpleString(); byte[] stringPayload = text.toString().getBytes("UTF-8"); payload = ByteBufAllocator.DEFAULT.buffer(stringPayload.length); payload.writeBytes(stringPayload); break; } catch (UnsupportedEncodingException e) { log.warn("Unable to send message: " + message.getMessageID() + " Cause: " + e.getMessage(), e); } default: ActiveMQBuffer bodyBuffer = message.getDataBuffer(); payload = ByteBufAllocator.DEFAULT.buffer(bodyBuffer.writerIndex()); payload.writeBytes(bodyBuffer.byteBuf()); break; } session.getProtocolHandler().send(messageId, address, qos, isRetain, payload, deliveryCount); }
final long messageID = newServerMessage.getMessageID(); final long consumerID = consumer.getID(); messagesToAck.put(newServerMessage.getMessageID(), new Pair<>(consumer.getID(), length));
protected void sendServerMessage(ICoreMessage message, String txID) throws ActiveMQStompException { StompSession stompSession = getSession(txID); if (stompSession.isNoLocal()) { message.putStringProperty(CONNECTION_ID_PROP, getID().toString()); } if (isEnableMessageID()) { message.putStringProperty("amqMessageId", "STOMP" + message.getMessageID()); } try { if (minLargeMessageSize == -1 || (message.getBodyBuffer().writerIndex() < minLargeMessageSize)) { stompSession.sendInternal(message, false); } else { stompSession.sendInternalLarge((CoreMessage)message, false); } } catch (Exception e) { throw BUNDLE.errorSendMessage(message, e).setHandler(frameHandler); } }
protected void sendServerMessage(ICoreMessage message, String txID) throws ActiveMQStompException { try { StompSession stompSession = getSession(txID); if (stompSession.isNoLocal()) { message.putStringProperty(CONNECTION_ID_PROP, getID().toString()); } if (isEnableMessageID()) { message.putStringProperty("amqMessageId", "STOMP" + message.getMessageID()); } if (minLargeMessageSize == -1 || (message.getBodyBuffer().writerIndex() < minLargeMessageSize)) { stompSession.sendInternal(message, false); } else { stompSession.sendInternalLarge((CoreMessage)message, false); } } catch (Exception e) { throw BUNDLE.errorSendMessage(message, e).setHandler(frameHandler); } }
@Override public void setOriginalHeaders(ServerMessage otherServerMessage, MessageReference originalReference, boolean expiry) { ICoreMessage other = otherServerMessage.getICoreMessage(); SimpleString originalQueue = other.getSimpleStringProperty(Message.HDR_ORIGINAL_QUEUE); if (originalQueue != null) { message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalQueue); } else if (originalReference != null) { message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalReference.getQueue().getName()); } if (other.containsProperty(Message.HDR_ORIG_MESSAGE_ID)) { message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, other.getSimpleStringProperty(Message.HDR_ORIGINAL_ADDRESS)); message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getLongProperty(Message.HDR_ORIG_MESSAGE_ID)); } else { message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, new SimpleString(other.getAddress())); message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getMessageID()); } // reset expiry message.setExpiration(0); if (expiry) { long actualExpiryTime = System.currentTimeMillis(); message.putLongProperty(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime); } // TODO ASk clebert //message.bufferValid = false; }
public static MessageDispatch createMessageDispatch(MessageReference reference, ICoreMessage message, WireFormat marshaller, AMQConsumer consumer) throws IOException { ActiveMQMessage amqMessage = toAMQMessage(reference, message, marshaller, consumer); //we can use core message id for sequenceId amqMessage.getMessageId().setBrokerSequenceId(message.getMessageID()); MessageDispatch md = new MessageDispatch(); md.setConsumerId(consumer.getId()); md.setRedeliveryCounter(reference.getDeliveryCount() - 1); md.setDeliverySequenceId(amqMessage.getMessageId().getBrokerSequenceId()); md.setMessage(amqMessage); ActiveMQDestination destination = amqMessage.getDestination(); md.setDestination(destination); return md; }