简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM