Search in sources :

Example 1 with ExternalMessage

use of io.spine.server.integration.ExternalMessage in project core-java by SpineEventEngine.

the class DelegatingRejectionDispatcher method getExternalDispatcher.

/**
 * Wraps this dispatcher to an external rejection dispatcher.
 *
 * @return the external rejection dispatcher proxying calls to the underlying instance
 */
public ExternalMessageDispatcher<I> getExternalDispatcher() {
    return new ExternalMessageDispatcher<I>() {

        @Override
        public Set<ExternalMessageClass> getMessageClasses() {
            final Set<RejectionClass> rejectionClasses = delegate.getExternalRejectionClasses();
            return ExternalMessageClass.fromRejectionClasses(rejectionClasses);
        }

        @Override
        public Set<I> dispatch(ExternalMessageEnvelope envelope) {
            final ExternalMessage externalMessage = envelope.getOuterObject();
            final Rejection rejection = unpack(externalMessage.getOriginalMessage());
            final Set<I> ids = delegate.dispatchRejection(RejectionEnvelope.of(rejection));
            return ids;
        }

        @Override
        public void onError(ExternalMessageEnvelope envelope, RuntimeException exception) {
            final MessageClass messageClass = envelope.getMessageClass();
            final String messageId = Stringifiers.toString(envelope.getId());
            final String errorMessage = format("Error dispatching external rejection (class: %s, id: %s)", messageClass, messageId);
            log().error(errorMessage, exception);
        }
    };
}
Also used : Rejection(io.spine.core.Rejection) ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) ExternalMessageClass(io.spine.server.integration.ExternalMessageClass) MessageClass(io.spine.type.MessageClass) ExternalMessageEnvelope(io.spine.server.integration.ExternalMessageEnvelope) ExternalMessageDispatcher(io.spine.server.integration.ExternalMessageDispatcher) RejectionClass(io.spine.core.RejectionClass) ExternalMessage(io.spine.server.integration.ExternalMessage)

Example 2 with ExternalMessage

use of io.spine.server.integration.ExternalMessage in project core-java by SpineEventEngine.

the class DelegatingEventDispatcher method asEventEnvelope.

private static EventEnvelope asEventEnvelope(ExternalMessageEnvelope envelope) {
    final ExternalMessage externalMessage = envelope.getOuterObject();
    final Event event = unpack(externalMessage.getOriginalMessage());
    return EventEnvelope.of(event);
}
Also used : Event(io.spine.core.Event) ExternalMessage(io.spine.server.integration.ExternalMessage)

Example 3 with ExternalMessage

use of io.spine.server.integration.ExternalMessage in project core-java by SpineEventEngine.

the class DelegatingEventDispatcherShould method expose_external_dispatcher_that_delegates_onError.

@Test
public void expose_external_dispatcher_that_delegates_onError() {
    final ExternalMessageDispatcher<String> extMessageDispatcher = delegatingDispatcher.getExternalDispatcher();
    final TestEventFactory factory = TestEventFactory.newInstance(getClass());
    final StringValue eventMsg = newUuidValue();
    final Event event = factory.createEvent(eventMsg);
    final ExternalMessage externalMessage = ExternalMessages.of(event, BoundedContext.newName(getClass().getName()));
    final ExternalMessageEnvelope externalMessageEnvelope = ExternalMessageEnvelope.of(externalMessage, eventMsg);
    final RuntimeException exception = new RuntimeException("test external dispatcher delegating onError");
    extMessageDispatcher.onError(externalMessageEnvelope, exception);
    assertTrue(delegate.onErrorCalled());
}
Also used : TestEventFactory(io.spine.server.command.TestEventFactory) Event(io.spine.core.Event) ExternalMessageEnvelope(io.spine.server.integration.ExternalMessageEnvelope) ExternalMessage(io.spine.server.integration.ExternalMessage) StringValue(com.google.protobuf.StringValue) Test(org.junit.Test)

Aggregations

ExternalMessage (io.spine.server.integration.ExternalMessage)3 Event (io.spine.core.Event)2 ExternalMessageEnvelope (io.spine.server.integration.ExternalMessageEnvelope)2 StringValue (com.google.protobuf.StringValue)1 Rejection (io.spine.core.Rejection)1 RejectionClass (io.spine.core.RejectionClass)1 TestEventFactory (io.spine.server.command.TestEventFactory)1 ExternalMessageClass (io.spine.server.integration.ExternalMessageClass)1 ExternalMessageDispatcher (io.spine.server.integration.ExternalMessageDispatcher)1 MessageClass (io.spine.type.MessageClass)1 Test (org.junit.Test)1