3/30/2011

About the E-Mail Listener in Liferay ...

Some weeks ago, I wrote about creating an own email listener:


http://liferay-blogging.blogspot.com/2011/02/how-to-create-e-mail-listener-in.html


If you do this, you need a way to register your email listener. One way could be in a hook or in a portlet that, when being initialized, registers the email listener. But beware: Your listeners are not unregistered, when you redeploy your portlet / hook ! After a redeployment you suddenly have 2 (or more) listeners doing your work. The solution must be to call unregister before registering a new one.


This might be a solution:


EmailListener listener = new EmailListener();
MessageBus messageBus = MessageBusUtil.getMessageBus();
MessageBusUtil.unregisterMessageListener(DestinationNames.MAIL, listener);
MessageBusUtil.registerMessageListener(DestinationNames.MAIL, listener);

This only works if the equals() method of your listener is properly configured and (for example) checks for the className.



If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)


If you have any questions, feel free to leave a comment.