@Override public org.apache.activemq.artemis.api.core.Message copy() { ensureDataIsValid(); ReadableBuffer view = data.duplicate().rewind(); byte[] newData = new byte[view.remaining()]; // Copy the full message contents with delivery annotations as they will // be trimmed on send and may become useful on the broker at a later time. view.get(newData); AMQPMessage newEncode = new AMQPMessage(this.messageFormat, newData, extraProperties, coreMessageObjectPools); newEncode.setMessageID(this.getMessageID()); return newEncode; }
@Override public String toString() { return "AMQPMessage [durable=" + isDurable() + ", messageID=" + getMessageID() + ", address=" + getAddress() + ", size=" + getEncodeSize() + ", applicationProperties=" + getApplicationProperties() + ", properties=" + getProperties() + ", extraProperties = " + getExtraProperties() + "]"; }
@Override public String getStringProperty(String key) throws ActiveMQPropertyConversionException { if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { return getProperties().getSubject(); } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) { return getConnectionID(); } else { return (String) getApplicationPropertiesMap().get(key); } }
@Override public String toString() { return "AMQPMessage [durable=" + isDurable() + ", messageID=" + getMessageID() + ", address=" + getAddress() + ", size=" + getEncodeSize() + ", applicationProperties=" + applicationProperties + ", properties=" + properties + ", extraProperties = " + getExtraProperties() + "]"; }
@Override public AMQPMessage setAddress(String address) { setAddress(cachedAddressSimpleString(address)); return this; }
Section body = message.getProtonMessage().getBody(); ServerJMSMessage result; if (isContentType(SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString(), message.getProtonMessage())) { result = createObjectMessage(message.getMessageID(), coreMessageObjectPools); } else if (isContentType(OCTET_STREAM_CONTENT_TYPE, message.getProtonMessage()) || isContentType(null, message.getProtonMessage())) { result = createBytesMessage(message.getMessageID(), coreMessageObjectPools); } else { Charset charset = getCharsetForTextualContent(message.getProtonMessage().getContentType()); if (charset != null) { result = createTextMessage(message.getMessageID(), coreMessageObjectPools); } else { result = createMessage(message.getMessageID(), coreMessageObjectPools); if (isContentType(SERIALIZED_JAVA_OBJECT_CONTENT_TYPE.toString(), message.getProtonMessage())) { result = createObjectMessage(message.getMessageID(), payload.getArray(), payload.getArrayOffset(), payload.getLength(), coreMessageObjectPools); } else if (isContentType(OCTET_STREAM_CONTENT_TYPE, message.getProtonMessage())) { result = createBytesMessage(message.getMessageID(), payload.getArray(), payload.getArrayOffset(), payload.getLength(), coreMessageObjectPools); } else { Charset charset = getCharsetForTextualContent(message.getProtonMessage().getContentType()); if (StandardCharsets.UTF_8.equals(charset)) { ByteBuffer buf = ByteBuffer.wrap(payload.getArray(), payload.getArrayOffset(), payload.getLength()); result = createTextMessage(message.getMessageID(), String.valueOf(chars), coreMessageObjectPools); } catch (CharacterCodingException e) { result = createBytesMessage(message.getMessageID(), payload.getArray(), payload.getArrayOffset(), payload.getLength(), coreMessageObjectPools); result = createBytesMessage(message.getMessageID(), payload.getArray(), payload.getArrayOffset(), payload.getLength(), coreMessageObjectPools);
private boolean checkMessageProperties(AMQPMessage message, Map<String, Object> expectedProperties) { assertNotNull(message); assertNotNull(server.getNodeID()); assertNotNull(message.getConnectionID()); assertEquals(message.getAddress(), expectedProperties.get(ADDRESS)); assertEquals(message.isDurable(), expectedProperties.get(DURABLE)); Properties props = message.getProperties(); assertEquals(props.getCorrelationId(), expectedProperties.get(CORRELATION_ID)); assertEquals(props.getReplyTo(), expectedProperties.get(REPLY_TO)); assertEquals(props.getMessageId(), expectedProperties.get(MESSAGE_ID)); Header header = message.getHeader(); assertEquals(header.getDurable(), expectedProperties.get(DURABLE)); assertEquals(header.getTtl().toString(), expectedProperties.get(TIME_TO_LIVE).toString()); assertEquals(header.getPriority().toString(), expectedProperties.get(PRIORITY).toString()); return true; }
@Override public Object getObjectProperty(String key) { if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { if (getProperties() != null) { return getProperties().getSubject(); } } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) { return getConnectionID(); } else if (key.equals(MessageUtil.JMSXGROUPID)) { return getGroupID(); } else if (key.equals(MessageUtil.JMSXUSERID)) { return getAMQPUserID(); } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) { if (getProperties() != null && getProperties().getCorrelationId() != null) { return AMQPMessageIdHelper.INSTANCE.toCorrelationIdString(getProperties().getCorrelationId()); } } else { Object value = getApplicationPropertiesMap().get(key); if (value instanceof UnsignedInteger || value instanceof UnsignedByte || value instanceof UnsignedLong || value instanceof UnsignedShort) { return ((Number)value).longValue(); } else { return value; } } return null; }
@Override public org.apache.activemq.artemis.api.core.Message copy() { checkBuffer(); ReadableBuffer view = data.duplicate(); byte[] newData = new byte[view.remaining() - (messagePaylodStart - headerEnds)]; view.position(0).limit(headerEnds); view.get(newData, 0, headerEnds); view.clear(); view.position(messagePaylodStart); view.get(newData, headerEnds, view.remaining()); AMQPMessage newEncode = new AMQPMessage(this.messageFormat, newData, extraProperties, coreMessageObjectPools); newEncode.setDurable(isDurable()).setMessageID(this.getMessageID()); return newEncode; }
buffer.readBytes(data); AMQPMessage amqpMessage = new AMQPMessage(messageFormat, data, null); amqpMessage.setMessageID(message.getInnerMessage().getMessageID()); amqpMessage.setReplyTo(coreMessage.getReplyTo()); return amqpMessage;
return getConnectionID(); } else if (key.equals(MessageUtil.JMSXGROUPID)) { return getGroupID(); } else if (key.equals(MessageUtil.JMSXGROUPSEQ)) { return getGroupSequence(); } else if (key.equals(MessageUtil.JMSXUSERID)) { return getAMQPUserID(); } else if (key.equals(MessageUtil.CORRELATIONID_HEADER_NAME.toString())) { if (properties != null && properties.getCorrelationId() != null) { Object value = getApplicationPropertiesMap(false).get(key); if (value instanceof UnsignedInteger || value instanceof UnsignedByte ||
@Override public void reencode() { parseHeaders(); getApplicationProperties(); getDeliveryAnnotations(); if (_header != null) getProtonMessage().setHeader(_header); if (_deliveryAnnotations != null) getProtonMessage().setDeliveryAnnotations(_deliveryAnnotations); if (_messageAnnotations != null) getProtonMessage().setMessageAnnotations(_messageAnnotations); if (applicationProperties != null) getProtonMessage().setApplicationProperties(applicationProperties); if (_properties != null) { if (address != null) { _properties.setTo(address.toString()); } getProtonMessage().setProperties(this._properties); } bufferValid = false; checkBuffer(); }
@Override public void reloadPersistence(ActiveMQBuffer record) { int size = record.readInt(); byte[] recordArray = new byte[size]; record.readBytes(recordArray); data = ReadableBuffer.ByteBufferReader.wrap(ByteBuffer.wrap(recordArray)); // Message state is now that the underlying buffer is loaded but the contents // not yet scanned, once done the message is fully populated and ready for dispatch. // Force a scan now and tidy the state variables to reflect where we are following // this reload from the store. scanMessageData(); messageDataScanned = true; modified = false; // Message state should reflect that is came from persistent storage which // can happen when moved to a durable location. We must re-encode here to // avoid a subsequent redelivery from suddenly appearing with a durable header // tag when the initial delivery did not. if (!isDurable()) { setDurable(true); reencode(); } }
ReadableBuffer data, RoutingContext routingContext) throws Exception { AMQPMessage message = new AMQPMessage(messageFormat, data, null, coreMessageObjectPools); if (address != null) { message.setAddress(address); } else { address = message.getAddressSimpleString(); if (address == null) { rejectMessage(delivery, Symbol.valueOf("failed"), "Missing 'to' field for message sent to an anonymous producer"); PagingStore store = manager.getServer().getPagingManager().getPageStore(message.getAddressSimpleString()); if (store != null && store.isRejectingMessages()) {
@Override public long getTimestamp() { if (getProperties() != null && getProperties().getCreationTime() != null) { return getProperties().getCreationTime().getTime(); } else { return 0L; } }
@Override public SimpleString getAddressSimpleString() { if (address == null) { TypedProperties extraProperties = getExtraProperties(); // we first check if extraProperties is not null, no need to create it just to check it here if (extraProperties != null) { address = extraProperties.getSimpleStringProperty(ADDRESS_PROPERTY); } if (address == null) { // if it still null, it will look for the address on the getTo(); Properties properties = getProperties(); if (properties != null && properties.getTo() != null) { address = cachedAddressSimpleString(properties.getTo()); } } } return address; }
@Override public boolean isDurable() { if (durable != null) { return durable; } parseHeaders(); if (getHeader() != null && getHeader().getDurable() != null) { durable = getHeader().getDurable(); return durable; } else { return durable != null ? durable : false; } }
/** * Gets a ByteBuf from the Message that contains the encoded bytes to be sent on the wire. * <p> * When possible this method will present the bytes to the caller without copying them into * another buffer copy. If copying is needed a new Netty buffer is created and returned. The * caller should ensure that the reference count on the returned buffer is always decremented * to avoid a leak in the case of a copied buffer being returned. * * @param deliveryCount * The new delivery count for this message. * * @return a Netty ByteBuf containing the encoded bytes of this Message instance. */ public ReadableBuffer getSendBuffer(int deliveryCount) { checkBuffer(); if (deliveryCount > 1) { return createCopyWithNewDeliveryCount(deliveryCount); } else if (headerEnds != messagePaylodStart) { return createCopyWithoutDeliveryAnnotations(); } else { // Common case message has no delivery annotations and this is the first delivery // so no re-encoding or section skipping needed. return data.duplicate(); } }
@Override public String getStringProperty(String key) throws ActiveMQPropertyConversionException { if (key.equals(MessageUtil.TYPE_HEADER_NAME.toString())) { return properties.getSubject(); } else if (key.equals(MessageUtil.CONNECTION_ID_PROPERTY_NAME.toString())) { return getConnectionID(); } else { return (String) getApplicationPropertiesMap(false).get(key); } }
@Override public Message decode(ActiveMQBuffer buffer, Message record) { long id = buffer.readLong(); long format = buffer.readLong(); SimpleString address = buffer.readNullableSimpleString(); record = new AMQPMessage(format); record.reloadPersistence(buffer); record.setMessageID(id); if (address != null) { record.setAddress(address); } return record; }