2. What is mule requester?
• As its name may hint, its goal is to allow the
request of a resource at any point in a flow.
• This resource can be a file, a message (from
VM, JMS, AMQP, etc.), an e-mail, etc.
• It’s intended for resources that originally could
only be requested by message sources.
3. • If we want to consume messages from a queue on demand,
i.e. not consuming the message as soon as it’s put on the
queue but at a later stage, when a user calls an HTTP
inbound endpoint, for example.
• We cannot achieve this by using a JMS inbound endpoint,
since it will consume the message as soon as it’s put on the
queue.
• Thinking about a way of doing this, we could have a
stopped flow and activate it on demand but this would
cause the consumption of more than one message or a
clumsy implementation that would pick a message and stop
the flow again.
• Another option would be to use a component but this
would have to deal with the specifics of the transport,
leading to either one implementation per transport type or
a big component handling all the transports.
5. Some of its more common use cases
are :
• Load a file in the middle of a flow for
processing.
• Consume messages (one, N, all) from a queue
in the middle of a flow.
• Pull messages from a mail server on demand,
to use its data in an enricher for example.
6. Why releasing it as a Mule module?
• It’s reusable
• It’s simple
• It can be easily installed in MuleStudio
• It can be used with Maven
7. •Following the first example, let’s show a more complex one: consuming all the
messages from a queue on demand. Let’s assume that the use case is to get all those
messages after a user called an inbound HTTP endpoint (it could be any other kind of
Mule endpoint, e.g. Quartz).
First we have the flow with the starting entry point:
9. This flow does all the magic:
• First it requests a message from the queue ‘input’.
• If there is a message, it processes it (just logs the
payload in the example) and calls the same flow again,
to allow the processing of the next messages in queue.
• Otherwise, if there is no pending message in the
queue, it just logs the queue has been emptied and
finishes.
• This configuration also contains another example that
shows how to consume a file based on an expression
after calling an HTTP inbound endpoint.
10. Key feature of the module :
• Expressions support
• Possibility of throwing an exception if the
requested resource is null
• Automatic transformer: the return type of the
requester resource can be set to any type and
Mule will automatically try to transform it