Search in sources :

Example 1 with LambdaMessageProcessor

use of org.springframework.integration.handler.LambdaMessageProcessor in project spring-integration by spring-projects.

the class LambdaMessageProcessorTests method handle.

private void handle(GenericHandler<?> h) {
    LambdaMessageProcessor lmp = new LambdaMessageProcessor(h, String.class);
    lmp.setBeanFactory(mock(BeanFactory.class));
    lmp.processMessage(new GenericMessage<>("foo"));
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) BeanFactory(org.springframework.beans.factory.BeanFactory)

Example 2 with LambdaMessageProcessor

use of org.springframework.integration.handler.LambdaMessageProcessor in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the selector's accept method returns 'true'.
 * @param channel the recipient channel.
 * @param selector the selector.
 * @param <P> the selector source type.
 * @return the router spec.
 */
public <P> RecipientListRouterSpec recipient(MessageChannel channel, GenericSelector<P> selector) {
    MessageSelector messageSelector;
    if (selector instanceof MessageSelector) {
        messageSelector = (MessageSelector) selector;
    } else {
        messageSelector = isLambda(selector) ? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null)) : new MethodInvokingSelector(selector);
    }
    this.handler.addRecipient(channel, messageSelector);
    return _this();
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MethodInvokingSelector(org.springframework.integration.filter.MethodInvokingSelector)

Example 3 with LambdaMessageProcessor

use of org.springframework.integration.handler.LambdaMessageProcessor in project spring-integration by spring-projects.

the class RecipientListRouterSpec method recipient.

/**
 * Adds a recipient channel that will be selected if the the selector's accept method returns 'true'.
 * @param channelName the channel name.
 * @param selector the selector.
 * @param <P> the selector source type.
 * @return the router spec.
 */
public <P> RecipientListRouterSpec recipient(String channelName, GenericSelector<P> selector) {
    MessageSelector messageSelector;
    if (selector instanceof MessageSelector) {
        messageSelector = (MessageSelector) selector;
    } else {
        messageSelector = isLambda(selector) ? new MethodInvokingSelector(new LambdaMessageProcessor(selector, null)) : new MethodInvokingSelector(selector);
    }
    this.handler.addRecipient(channelName, messageSelector);
    return _this();
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MethodInvokingSelector(org.springframework.integration.filter.MethodInvokingSelector)

Example 4 with LambdaMessageProcessor

use of org.springframework.integration.handler.LambdaMessageProcessor in project spring-integration by spring-projects.

the class LambdaMessageProcessorTests method testMessageAsArgument.

@Test
public void testMessageAsArgument() {
    LambdaMessageProcessor lmp = new LambdaMessageProcessor(new GenericTransformer<Message<?>, Message<?>>() {

        @Override
        public Message<?> transform(Message<?> source) {
            return messageTransformer(source);
        }
    }, null);
    lmp.setBeanFactory(mock(BeanFactory.class));
    GenericMessage<String> testMessage = new GenericMessage<>("foo");
    Object result = lmp.processMessage(testMessage);
    assertSame(testMessage, result);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 5 with LambdaMessageProcessor

use of org.springframework.integration.handler.LambdaMessageProcessor in project spring-integration by spring-projects.

the class IntegrationFlowDefinition method filter.

/**
 * Populate a {@link MessageFilter} with {@link MethodInvokingSelector}
 * for the provided {@link GenericSelector}.
 * In addition accept options for the integration endpoint using {@link FilterEndpointSpec}.
 * Typically used with a Java 8 Lambda expression:
 * <pre class="code">
 * {@code
 *  .filter(Date.class, p -> p.after(new Date()), e -> e.autoStartup(false))
 * }
 * </pre>
 * @param payloadType the {@link Class} for desired {@code payload} type.
 * @param genericSelector the {@link GenericSelector} to use.
 * @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
 * @param <P> the source payload type.
 * @return the current {@link IntegrationFlowDefinition}.
 * @see LambdaMessageProcessor
 * @see FilterEndpointSpec
 */
public <P> B filter(Class<P> payloadType, GenericSelector<P> genericSelector, Consumer<FilterEndpointSpec> endpointConfigurer) {
    Assert.notNull(genericSelector, "'genericSelector' must not be null");
    MessageSelector selector = genericSelector instanceof MessageSelector ? (MessageSelector) genericSelector : (isLambda(genericSelector) ? new MethodInvokingSelector(new LambdaMessageProcessor(genericSelector, payloadType)) : new MethodInvokingSelector(genericSelector));
    return this.register(new FilterEndpointSpec(new MessageFilter(selector)), endpointConfigurer);
}
Also used : LambdaMessageProcessor(org.springframework.integration.handler.LambdaMessageProcessor) MessageSelector(org.springframework.integration.core.MessageSelector) MessageFilter(org.springframework.integration.filter.MessageFilter) MethodInvokingSelector(org.springframework.integration.filter.MethodInvokingSelector)

Aggregations

LambdaMessageProcessor (org.springframework.integration.handler.LambdaMessageProcessor)6 MessageSelector (org.springframework.integration.core.MessageSelector)3 MethodInvokingSelector (org.springframework.integration.filter.MethodInvokingSelector)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 Test (org.junit.Test)1 MessageFilter (org.springframework.integration.filter.MessageFilter)1 ClaimCheckInTransformer (org.springframework.integration.transformer.ClaimCheckInTransformer)1 ClaimCheckOutTransformer (org.springframework.integration.transformer.ClaimCheckOutTransformer)1 ExpressionEvaluatingTransformer (org.springframework.integration.transformer.ExpressionEvaluatingTransformer)1 GenericTransformer (org.springframework.integration.transformer.GenericTransformer)1 MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)1 MethodInvokingTransformer (org.springframework.integration.transformer.MethodInvokingTransformer)1 Transformer (org.springframework.integration.transformer.Transformer)1 Message (org.springframework.messaging.Message)1 GenericMessage (org.springframework.messaging.support.GenericMessage)1