2

I need to implement with the help of spring-intagration libraries a message pipeline. At the beginning, as I see now, it needs to contain several elements:

a. Messaging gateway,

@MessagingGateway(name = "entryGateway", defaultRequestChannel = "requestChannel")
public interface MessageGateway {
    public boolean  processMessage(Message<?> message);
}

which is called when I want to start the pipeline:

messageGateway.processMessage(message);

b. Channel for transmitting the messages:

@Bean
public MessageChannel requestChannel() {
        return new DirectChannel();
}

c.Router which decides then where flow the messages

@MessageEndpoint
@Component
public class MessageTypeRouter {
    Logger log = Logger.getLogger(MessageTypeRouter.class);

    @Router(inputChannel="requestChannel")
    public String processMessageByPayload(Message<?> message){...}

There can be many incoming messages in a small period of time, so I wanted to realize a channel (b) as QueueChannel:

@Bean
public MessageChannel requestChannel() {
        return new QueueChannel();
}

On the other hand I would like the router to start as soon as a message comes through gateway and the other messages to wait in the queue. But in this case I received an error, which said that I should have used a poller.

May be you could give me a piece of advice, how I can realize my scheme. Thank you in advance.

user2957954
  • 1,221
  • 2
  • 18
  • 39

1 Answers1

0

As we know with XML config we must declare a <poller> component and mark it with default="true". That allows any PollingConsumer endpoint to pick up the default Poller from the context.

With Java config we must declare a @Bean for similar purpose:

@Bean(name = PollerMetadata.DEFAULT_POLLER)
public PollerMetadata defaultPoller() {
    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(10));
    return pollerMetadata;
}

Where the PollerMetadata.DEFAULT_POLLER is specific constant to define the default poller. Although the same name is used from XML config in case of default="true".

From other side @Router annotation has poller attribute to specify something similar like we do with nested <poller> in XML.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • As you can see, I don't want to use polling semantics. I use message-driven gateway that actually isn't compatible with queueChannel, as I've read. The question is: how can I store multiple incoming messages sing message-driven semantics. – user2957954 Apr 29 '15 at 16:05
  • OK. How about `ExecutorChannel`? Any incoming message will wait for the free `Thread` to be processed in the internal `queue` of `ThreadPollTaskExecutor` – Artem Bilan Apr 29 '15 at 16:09
  • This is my pipleline: gateway -> channel -> Router -> further things. I need to implement Router and others as Runnable if I want to user executorChannel, don't I? – user2957954 Apr 29 '15 at 16:21
  • No. Spring Integration does that for you internally: just wraps `handleMessage` to the `Runnable` for the `TaskExecutor` – Artem Bilan Apr 29 '15 at 16:31