/** * Initializes {@link GenericSubscriptionQueryUpdateMessage} with incremental update of provided {@code * declaredType} and {@code metaData}. * * @param declaredType the type of the update * @param payload the payload of the update * @param metaData the metadata of the update */ public GenericSubscriptionQueryUpdateMessage(Class<U> declaredType, U payload, Map<String, ?> metaData) { super(new GenericMessage<>(declaredType, payload, metaData)); }
/** * Constructor to reconstruct an EventMessage using existing data. * * @param identifier The identifier of the Message * @param timestamp The timestamp of the Message creation * @param payload The payload of the message * @param metaData The meta data of the message */ public GenericEventMessage(String identifier, T payload, Map<String, ?> metaData, Instant timestamp) { this(new GenericMessage<>(identifier, payload, metaData), timestamp); }
/** * Initialize the response message with given {@code result} and {@code metaData}. * * @param result The result reported by the Query Handler, may not be {@code null} * @param metaData The meta data to contain in the message */ public GenericQueryResponseMessage(R result, Map<String, ?> metaData) { super(new GenericMessage<>(result, metaData)); }
/** * Initialize the response message with a specific {@code declaredResultType}, the given {@code result} as payload * and {@code metaData}. * * @param declaredResultType A {@link java.lang.Class} denoting the declared result type of this query response * message * @param result The result reported by the Query Handler, may be {@code null} * @param metaData The meta data to contain in the message */ public GenericQueryResponseMessage(Class<R> declaredResultType, R result, Map<String, ?> metaData) { super(new GenericMessage<>(declaredResultType, result, metaData)); }
/** * Creates a ResultMessage with the given {@code result} as the payload and {@code metaData} as the meta data. * * @param result the payload for the Message * @param metaData the meta data for the Message */ public GenericResultMessage(R result, Map<String, ?> metaData) { this(new GenericMessage<>(result, metaData)); }
/** * Initialize the response message with given {@code declaredResultType}, {@code exception} and {@code metaData}. * * @param declaredResultType The declared type of the Query Response Message to be created * @param exception The Exception describing the cause of an error * @param metaData The meta data to contain in the message */ public GenericQueryResponseMessage(Class<R> declaredResultType, Throwable exception, Map<String, ?> metaData) { super(new GenericMessage<>(declaredResultType, null, metaData), exception); }
/** * Creates a ResultMessage with the given {@code exception} and {@code metaData}. * * @param exception the Exception describing the cause of an error * @param metaData the meta data for the Message */ public GenericResultMessage(Throwable exception, Map<String, ?> metaData) { this(new GenericMessage<>(null, metaData), exception); }
@Override protected Message<T> withMetaData(MetaData metaData) { return new GenericMessage<>(this, metaData); }
/** * Initialize a DomainEventMessage originating from an Aggregate using existing data. * * @param type The domain type * @param aggregateIdentifier The identifier of the aggregate generating this message * @param sequenceNumber The message's sequence number * @param payload The application-specific payload of the message * @param metaData The MetaData to attach to the message * @param messageIdentifier The message identifier * @param timestamp The event's timestamp */ public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload, Map<String, ?> metaData, String messageIdentifier, Instant timestamp) { this(type, aggregateIdentifier, sequenceNumber, new GenericMessage<>(messageIdentifier, payload, metaData), timestamp); }
/** * Create a CommandMessage with the given {@code command} as payload. * * @param payload the payload for the Message * @param metaData The meta data for this message */ public GenericCommandMessage(T payload, Map<String, ?> metaData) { this(new GenericMessage<>(payload, metaData), payload.getClass().getName()); }
/** * Initializes the message with the given {@code payload}, {@code queryName} and expected {@code responseType}. * * @param payload The payload expressing the query * @param queryName The name identifying the query to execute * @param responseType The expected response type of type * {@link ResponseType} */ public GenericQueryMessage(T payload, String queryName, ResponseType<R> responseType) { this(new GenericMessage<>(payload, MetaData.emptyInstance()), queryName, responseType); }
/** * Initializes {@link GenericSubscriptionQueryUpdateMessage} with incremental update. * * @param payload payload of the message which represent incremental update */ public GenericSubscriptionQueryUpdateMessage(U payload) { this(new GenericMessage<>(payload, MetaData.emptyInstance())); }
/** * Creates a GenericEventMessage with given {@code payload} and given {@code metaData}. * * @param payload The payload of the EventMessage * @param metaData The MetaData for the EventMessage * @see #asEventMessage(Object) */ public GenericEventMessage(T payload, Map<String, ?> metaData) { this(new GenericMessage<>(payload, metaData), clock.instant()); }
private Object readResolve() { return new org.axonframework.messaging.GenericMessage<>(identifier, payload, metaData.getValues()); } }
/** * Initialize a DomainEventMessage originating from an Aggregate with the given {@code aggregateIdentifier}, * with given {@code sequenceNumber} and {@code payload} and {@code metaData}. * * @param type The domain type * @param aggregateIdentifier The identifier of the aggregate generating this message * @param sequenceNumber The message's sequence number * @param payload The application-specific payload of the message * @param metaData The MetaData to attach to the message */ public GenericDomainEventMessage(String type, String aggregateIdentifier, long sequenceNumber, T payload, Map<String, ?> metaData) { this(type, aggregateIdentifier, sequenceNumber, new GenericMessage<>(payload, metaData), clock.instant()); }
@Override public TestExecutor<T> andGiven(List<?> domainEvents) { for (Object event : domainEvents) { Object payload = event; MetaData metaData = null; if (event instanceof Message) { payload = ((Message) event).getPayload(); metaData = ((Message) event).getMetaData(); } this.givenEvents.add(new GenericDomainEventMessage<>(aggregateType.getSimpleName(), aggregateIdentifier, sequenceNumber++, new GenericMessage<>(payload, metaData), deadlineManager.getCurrentDateTime())); } return this; }
/** * Returns the given event as an EventMessage. If {@code event} already implements EventMessage, it is * returned as-is. If it is a Message, a new EventMessage will be created using the payload and meta data of the * given message. Otherwise, the given {@code event} is wrapped into a GenericEventMessage as its payload. * * @param event the event to wrap as EventMessage * @param <T> The generic type of the expected payload of the resulting object * @return an EventMessage containing given {@code event} as payload, or {@code event} if it already implements * EventMessage. */ @SuppressWarnings("unchecked") public static <T> EventMessage<T> asEventMessage(Object event) { if (EventMessage.class.isInstance(event)) { return (EventMessage<T>) event; } else if (event instanceof Message) { Message message = (Message) event; return new GenericEventMessage<>(message, clock.instant()); } return new GenericEventMessage<>(new GenericMessage<>((T) event), clock.instant()); }
/** * Returns the CommandMessage wrapped in this Message. * * @param serializer The serializer to deserialize message contents with * @return the CommandMessage wrapped in this Message */ public CommandMessage<?> getCommandMessage(Serializer serializer) { SimpleSerializedObject<byte[]> serializedPayload = new SimpleSerializedObject<>(this.serializedPayload, byte[].class, payloadType, payloadRevision); final Object payload = serializer.deserialize(serializedPayload); SerializedMetaData<byte[]> serializedMetaData = new SerializedMetaData<>(this.serializedMetaData, byte[].class); final MetaData metaData = serializer.deserialize(serializedMetaData); return new GenericCommandMessage<>(new GenericMessage<>(commandIdentifier, payload, metaData), commandName); }
@Override public <T> EventMessage<T> convertFromInboundMessage(Message<T> message) { MessageHeaders headers = message.getHeaders(); Map<String, ?> metaData = headers.entrySet() .stream() .filter(entry -> !entry.getKey().startsWith(AXON_MESSAGE_PREFIX)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); String messageId = Objects.toString(headers.get(MESSAGE_ID)); Long timestamp = headers.getTimestamp(); org.axonframework.messaging.GenericMessage<T> genericMessage = new org.axonframework.messaging.GenericMessage<>(messageId, message.getPayload(), metaData); if (headers.containsKey(AGGREGATE_ID)) { return new GenericDomainEventMessage<>(Objects.toString(headers.get(AGGREGATE_TYPE)), Objects.toString(headers.get(AGGREGATE_ID)), NumberUtils.convertNumberToTargetClass(headers.get(AGGREGATE_SEQ, Number.class), Long.class), genericMessage, () -> Instant.ofEpochMilli(timestamp)); } else { return new GenericEventMessage<>(genericMessage, () -> Instant.ofEpochMilli(timestamp)); } }
/** * Java Serialization API Method that provides a replacement to serialize, as the fields contained in this instance * are not serializable themselves. * * @return the GenericMessage to use as a replacement when serializing */ protected Object writeReplace() { return new GenericMessage<>(getIdentifier(), getPayload(), getMetaData()); } }