Use of a MailNotificationService in an existing process

Hello there,

I have an existing process for a simple email exchange. (Lisa asks her mother via email what she plans to do that day, Marge response with yes[…] or no[…] and the gateway in the subprocess know/processes the response)


But the sub-process should now start automatically when Marge’s response arrives. I try it first with an call activity (see below). But with this starts the second process (NotifyProcess) directly (so without the answer already arrived in Lisa’s mailbox)…


NotifyProcess:


I think the main problem is the use of my ReactOnIncomingMail.java (see below, similar to MailNotificationService.java from the camunda bpm mail (github.com) print example), because it says class is never used
So at first the main question is maybe how to use the React on incoming Mails feature :sweat_smile: In the printProcess example there is only one class, but at first Lisa has to send an email.

But maybe someone has an idea how I can use the MailNotificationService correctly for my example :slight_smile:

@SpringBootApplication
@ProcessApplication(name = "Notify new Mail incoming")
public class ReactOnIncomingMail extends ServletProcessApplication {

    private MailConfiguration configuration;
    private MailNotificationService notificationService;

    @PostDeploy
    public void startService(ProcessEngine processEngine) throws Exception {
        RuntimeService runtimeService = processEngine.getRuntimeService();

        configuration = MailConfigurationFactory.getConfiguration();
        notificationService = new MailNotificationService(configuration);

        notificationService.registerMailHandler(mail -> {
            runtimeService.startProcessInstanceByKey("notifyPrz",
                    Variables.createVariables()
                            .putValue("mail", mail)
                    //.putValue("invoice", getInvoicePath())
            );
        });

        notificationService.start();
    }
[...]

Hello @KameraUndA ,

when a mail arrives, you will start a process in your MailHandler. For this example, I would use a message correlation.

Try to correlate a message and wait for it with an intermediate message catch event inside the upper process.

The problem with the process you designed is that this NotifyProcess will be started whenever a mail arrives but has no link towards the upper process which you would expect to have a mail arriving.

Hope this helps

Jonathan

1 Like

So if I understand you correctly, I should do more like the following?


At the very beginning I had already tried to solve the problem with the message events.
But I’m still/now struggling again with the problem of how to combine a message event with an email (inbox).
Your tutorial which is the closest (at least the one I found) works only with POST methods:
Tutorial: Messaging with BPMN - YouTube

Is it maybe enough to do the correlation in the MailHandler? (If so, I have to see how exactly this works for the case :sweat_smile:)

Hello @KameraUndA ,

this is for a now a simple implementation. The MailHandler will need to be more complex in its implementation to fully serve your needs I think.

My idea behind this is that the MailHandler reacts on an incoming mail by sending a message to the Message API of the process engine as the pattern you describe is an async request/response. But your possibilities are unlimited regarding the mapping potential and will completely depend on your use case.

Jonathan

1 Like