user1760178
user1760178

Reputation: 6657

How to access Payload and MuleMessage in @Processor method

I have been working with implementing my custom processors using the Mule Devkit.

I have created the project with "mule-devkit-archetype-generic" archetype. It has given me the class with annotations "@Module" and "@Processor"

I can pass a parameter to my processor method.

But I couldn't get a way to access MuleMessage and Payload inside my @Processor method.

How can I achieve this?

Upvotes: 0

Views: 1206

Answers (1)

David Dossot
David Dossot

Reputation: 33413

To access the payload use:

@Payload final DESIRED_TYPE payload

replacing DESIRED_TYPE with the type you want and Mule will auto-transform the current payload to the desired type.

For example, this gives you a byte payload:

@Payload final byte[] payload

To access the MuleMessage, you actually access the MuleEvent and get the message from it. For this you need to add the @Inject annotation on your @Processor method and add a MuleEvent muleEvent argument to your processor method.

UPDATE 2017/08/31 using Mule 3.8.1

DevKit now generates a compile error if you try to annotate @Processor with @Inject. The error message states that if you simply add a MuleEvent or MuleMessage parameter to your @Processor method, DevKit will properly inject the parameters.

Upvotes: 2

Related Questions