How to register Handler

Hi,
i want to start my process as soon as a mail is received. I got the connector example as https://github.com/camunda/camunda-bpm-mail/tree/master/examples/print-service

In HOw to use section is says to register handler

Can someone tell me how to register a handler in Camunda in step by step manner. Or any help or reference link

Thanks
Aj

@ajay, The documentation itself has the example how to register the handler and start the service. Handler is nothing but a Consumer function for the function notificationService.registerMailHandler(...)

MailNotificationService.java
 public void registerMailHandler(Consumer<Mail> consumer) {
  	MessageTransformationHandler handler = new MessageTransformationHandler(consumer,
    configuration.downloadAttachments(), configuration.getAttachmentPath());
    registerMessageHandler(handler);
 }

public void registerMailHandler(Consumer<Mail> consumer) will be decorated as like below. This is how handlers are registered and started:

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

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

    notificationService.start();

Refer this example:

Thanks @aravindhrs,

I registered my handler in the my main class extending ServletProcessApplication.
I am able to achieve what i required.


Thanks
Aj

@aravindhrs: I am a Camunda newbie… I have Camunda running under a Wildfly. I am not clear how (in which object / file) I have to enter / call the example handler? So where do I have to put the file “MailNotifiactionService.java” and where do I have to enter it, so that the Process Engine uses it?
And how do I access it in the start event of the Camunda workflow?
Thanks for a little support and sorry for the basic questions :slight_smile:

Hi @Guddy,

if you are asking about the camunda-bpm-mail community extension, you can find the installation instruction for wildfly here: camunda-bpm-mail/shared-process-engine-wildfly.md at master · camunda-community-hub/camunda-bpm-mail · GitHub

Hope this helps, Ingo

Hi @Ingo_Richtsmeier . Thanks, the installation itself worked, the extension runs under Wildfly. Send mail and poll mail also works, but the “react on incoming mails” I have not yet got to run. I lack the knowledge where (in which script) I have to enter the following code:

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

notificationService.registerMailHandler(mail → {
runtimeService.startProcessInstanceByKey(“printProcess”,
Variables.createVariables()
.putValue(“mail”, mail)
.putValue(“invoice”, getInvoicePath()));
});

And how the start event in the modeler (listener) must look exactly at the end…

I would like to make my question more specific: How do I bring the Java file: MailNotificationService.java into the Camunda engine, resp. into the mail engine? I have never done this before… what steps are needed for this in my Camunda wildfly environment?
thank you for some help :slight_smile: