简体   繁体   中英

Apache camel IMAP multiple consumers of same mail account

I have application which allows dynamic creation and starting of routes. For example user can create route from IMAP to file and start it.

Problem: Multiple routes reading from same mail account through IMAP.

Caused by: org.apache.camel.FailedToStartRouteException: Failed to start route c1152_route because of Multiple consumers for the same endpoint is not allowed: imap://localhost:3143?delay=1000&password=xxxxxx&searchTerm.fromSentDate=now-24h&searchTerm.unseen=false&username=user@user

I've tried two approaches:

1.Creating additional single route from IMAP to multiple recipient routes. This one works but I'm not sure about this solution. It requires additional checks on starting/stopping of route because few routes might be dependent on this one.

from(imap())
   .recipientList(imapMsgToDirectChannelRouter())

2.Creating IMAP endpoints with unique uri. For example unique searchTerm.fromSentDate for each routes. This one also works.

Is there any better solution to this problem?

I would definitely go for option#1 (recipientList).

I do not understand why would have to stop & start the 'master' route (the "imap" one). Depending on the recipients you add or remove, you would start and stop the corresponding child routes, but not touch the master one.

I'm thinking on something like this:

from("imap:...")
  .id("master-route")
  .recipientList( simple("bean:computeRecipients") )
  .parallelProcessing();

Where the on-the-fly calculation of the exact list of recipients is delegated to some bean. This way, you do not have to touch the "master-route", instead just make the bean aware of the recipients

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