0
votes

I am in my second week of exploring with MULE. My requirement is to either read a database or read a file based on the input from http endpoint. I am trying to use a CHOICE in the flow and determine the nature of input and then flow out in different direction. But my problem is that i am not sure how to set the message with the query value or file value.

Can anybody help me with some inputs?

1

1 Answers

1
votes

Kindly check out this module

https://github.com/mulesoft/mule-requester-module

It can request a resource at any point in a flow. It's for resources originally only requested by message sources.

use cases are:

  • Load a file in the middle of a flow
  • 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.

Its a simple devkit wrapper around the typical muleContext.getClient() call

public Object request(String resource, @Optional @Default("1000") long timeout, @Optional String returnClass, @Optional Boolean throwExceptionOnTimeout) throws MuleException {
        MuleMessage message = muleContext.getClient().request(resource, timeout);
        Object result = null;
        if (message != null)
        {
            result = message.getPayload();
            if (returnClass != null)
            {
                try {
                    Transformer transformer = muleContext.getRegistry().lookupTransformer(DataTypeFactory.create(result.getClass()), DataTypeFactory.create(Class.forName(returnClass)));
                    result = transformer.transform(result);
                } catch (ClassNotFoundException e) {
                    throw new DefaultMuleException(e);
                }
            }
        } else if (Boolean.TRUE.equals(throwExceptionOnTimeout))
        {
            throw new DefaultMuleException("No message received in the configured timeout - " + timeout);
        }
        return result;
    }