Java Code Examples for org.eclipse.microprofile.reactive.messaging.Acknowledgment#Strategy

The following examples show how to use org.eclipse.microprofile.reactive.messaging.Acknowledgment#Strategy . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediatorConfigurationSupport.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
public Acknowledgment.Strategy processSuppliedAcknowledgement(List<?> incomings,
        Supplier<Acknowledgment.Strategy> supplier) {
    Acknowledgment.Strategy result = supplier.get();
    if (!incomings.isEmpty()) {
        return result;
    } else if (result != null) {
        throw ex.definitionExceptionUnsupported("@Outgoing", methodAsString);
    }
    return null;
}
 
Example 2
Source File: MediatorConfigurationSupport.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
public ValidationOutput validate(Shape shape, Acknowledgment.Strategy acknowledgment) {
    switch (shape) {
        case SUBSCRIBER:
            return validateSubscriber();
        case PUBLISHER:
            return validatePublisher();
        case PROCESSOR:
            return validateProcessor(acknowledgment);
        case STREAM_TRANSFORMER:
            return validateStreamTransformer(acknowledgment);
        default:
            throw ex.illegalStateExceptionForValidate(shape);
    }
}
 
Example 3
Source File: MediatorConfigurationSupport.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
public Acknowledgment.Strategy processDefaultAcknowledgement(Shape shape,
        MediatorConfiguration.Consumption consumption) {
    if (shape == Shape.STREAM_TRANSFORMER) {
        if (consumption == MediatorConfiguration.Consumption.STREAM_OF_PAYLOAD) {
            return Acknowledgment.Strategy.PRE_PROCESSING;
        } else {
            return Acknowledgment.Strategy.MANUAL;
        }
    } else if (shape == Shape.PROCESSOR) {
        if (consumption == MediatorConfiguration.Consumption.PAYLOAD) {
            return Acknowledgment.Strategy.POST_PROCESSING;
        } else if (consumption == MediatorConfiguration.Consumption.MESSAGE
                || consumption == MediatorConfiguration.Consumption.STREAM_OF_MESSAGE) {
            return Acknowledgment.Strategy.MANUAL;
        } else {
            return Acknowledgment.Strategy.PRE_PROCESSING;
        }
    } else if (shape == Shape.SUBSCRIBER) {
        if (consumption == MediatorConfiguration.Consumption.STREAM_OF_MESSAGE
                || consumption == MediatorConfiguration.Consumption.MESSAGE) {
            return Acknowledgment.Strategy.MANUAL;
        } else {
            return Acknowledgment.Strategy.POST_PROCESSING;
        }
    } else {
        return Acknowledgment.Strategy.POST_PROCESSING;
    }
}
 
Example 4
Source File: DefaultMediatorConfiguration.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Override
public Acknowledgment.Strategy getAcknowledgment() {
    return acknowledgment;
}
 
Example 5
Source File: MediatorConfigurationSupport.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
private ValidationOutput validateStreamTransformer(Acknowledgment.Strategy acknowledgment) {
    // 1.  Publisher<Message<O>> method(Publisher<Message<I>> publisher)
    // 2. Publisher<O> method(Publisher<I> publisher) - Dropped
    // 3. PublisherBuilder<Message<O>> method(PublisherBuilder<Message<I>> publisher)
    // 4. PublisherBuilder<O> method(PublisherBuilder<I> publisher) - Dropped

    // The case 2 and 4 have been dropped because it is not possible to acknowledge the messages automatically as we can't know when
    // the acknowledgment needs to happen. This has been discussed during the MP Reactive hangout, Sept. 11th, 2018.

    // But, they can be managed when ack is set to none or pre-processing(default)

    MediatorConfiguration.Production production;
    MediatorConfiguration.Consumption consumption;
    boolean useBuilderTypes;

    // The mediator produces and consumes a stream
    GenericTypeAssignable.Result returnTypeGenericCheck = returnTypeAssignable.check(Message.class, 0);
    if (returnTypeGenericCheck == GenericTypeAssignable.Result.NotGeneric) {
        throw ex.definitionExpectedReturnedParam("@Outgoing", methodAsString, "Publisher");
    }
    production = returnTypeGenericCheck == GenericTypeAssignable.Result.Assignable
            ? MediatorConfiguration.Production.STREAM_OF_MESSAGE
            : MediatorConfiguration.Production.STREAM_OF_PAYLOAD;

    GenericTypeAssignable.Result firstParamTypeGenericCheck = firstMethodParamTypeAssignable
            .check(Message.class, 0);
    if (firstParamTypeGenericCheck == GenericTypeAssignable.Result.NotGeneric) {
        throw ex.definitionExpectedConsumendParam("@Incoming", methodAsString, "Publisher");
    }
    consumption = firstParamTypeGenericCheck == GenericTypeAssignable.Result.Assignable
            ? MediatorConfiguration.Consumption.STREAM_OF_MESSAGE
            : MediatorConfiguration.Consumption.STREAM_OF_PAYLOAD;

    useBuilderTypes = ClassUtils.isAssignable(returnType, PublisherBuilder.class);

    // Post Acknowledgement is not supported
    if (acknowledgment == Acknowledgment.Strategy.POST_PROCESSING) {
        throw ex.definitionAutoAckNotSupported("@Incoming & @Outgoing", methodAsString);
    }

    // Validate method and be sure we are not in the case 2 and 4.
    if (consumption == MediatorConfiguration.Consumption.STREAM_OF_PAYLOAD
            && (acknowledgment == Acknowledgment.Strategy.MANUAL)) {
        throw ex.definitionManualAckNotSupported("@Incoming & @Outgoing", methodAsString);
    }

    if (production == MediatorConfiguration.Production.STREAM_OF_PAYLOAD
            && acknowledgment == Acknowledgment.Strategy.MANUAL) {
        throw ex.definitionManualAckNotSupported("@Incoming & @Outgoing", methodAsString);
    }

    if (useBuilderTypes) {
        //TODO Test validation.

        // Ensure that the parameter is also using the MP Reactive Streams Operator types.
        Class<?> paramClass = parameterTypes[0];
        if (!ClassUtils.isAssignable(paramClass, PublisherBuilder.class)) {
            throw ex.definitionProduceConsume("@Incoming & @Outgoing", methodAsString);
        }
    }

    // TODO Ensure that the parameter is also a publisher builder.

    return new ValidationOutput(production, consumption, useBuilderTypes);
}
 
Example 6
Source File: QuarkusMediatorConfiguration.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Acknowledgment.Strategy getAcknowledgment() {
    return acknowledgment;
}
 
Example 7
Source File: QuarkusMediatorConfiguration.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void setAcknowledgment(Acknowledgment.Strategy acknowledgment) {
    this.acknowledgment = acknowledgment;
}
 
Example 8
Source File: MediatorConfiguration.java    From smallrye-reactive-messaging with Apache License 2.0 votes vote down vote up
Acknowledgment.Strategy getAcknowledgment();