动态阿帕奇骆驼路线/背景设计问题 [英] Design question on dynamic Apache camel routes/context
问题描述
我们有在其上的系统中发生的事件的发布的ActiveMQ。该项目涉及的用户添加实体他们的观察名单,每当有这些实体的事件,我想的电子邮件被发送到感兴趣的与会者。
We have ActiveMQ onto which the events that happen in the system are published. The project involves users adding entities to their watch-list and whenever there are events on those entities I would like an email to be sent out to the interested participants.
用例大致翻译对某一前pressing在目录和电子邮件中的产品信息页面的兴趣被发送,只要任何活动发生在该产品(价格下跌,有一个积极的评价等。,)。我曾仿照这种互动为骆驼的路线。
The use-case roughly translates to some one expressing an interest in a product information page on the catalog and an email being sent whenever any activity happens on that product (price goes down, there is a positive review etc.,). I had modelled this interaction as a Camel route.
因此,举例来说,如果用户说,每当这个产品的评级等于5发邮件给我,那么下面的路线将被添加到骆驼背景:
So, for example, if the user says email me whenever this product's rating equals 5, then the following route would be added to the camel context:
from("activemq:topic:events.product.save").filter().xpath("/object[<object id>]/rating").isEqualTo("5").to("email:<user's email>")
同样的,如果用户希望每当有一个产品的新注释被通知
,另一路由将创建等等。这可能,最终每个用户开始加入自己感兴趣的手表创造数千个路线。
Similarly if the user wants to be notified whenever there is a new comment on a product, another route would be created and so on. This could potentially, end up creating thousands of routes as each user starts adding their watches of interest.
这是我有一些问题是:
-
这是创建动态路由的一种可接受的方式?我正在考虑的一种选择是使用收件人列表。但我一直没能拿出一个解决方案,将使其优雅的邮件路由到一个能返回收件人列表豆。例如,对于上述情况说明会的豆有一堆的if-else,看看哪些收件人列表返回?
Is this an acceptable way of creating dynamic routes? One option I am considering is to use recipient lists. But I haven't been able to come up with a solution that would make it elegant to route messages to the bean that would return the recipient list. For example for the case explained above would the bean have a bunch of if-else to see which recipient list to return?
该camelcontext必须从一个XML文件,但都没法坚持了现有航线的装载路线的方法。什么是最简单的(高效)的方式来保存这些动态创建的路线?这个线程在骆驼用户列表总结了我请求。
The camelcontext has a method to load routes from a xml file but no method to persist the existing routes. What would be simplest (and efficient) way to persist these dynamically created routes? This thread in the camel-users list sums up my request.
推荐答案
鉴于您的订购需求的动态性,你应该使用一个数据库来存储,而信息不是试图建立动态路由。这是一个更具扩展性/恰当地使用技术...
Given the dynamic nature of your subscription requirements, you should use a database to store the information rather than trying to create dynamic routes. This is a much more scalable/appropriate use of technology...
然后你就可以只需要一个静态路由或一个 POJO消费者(见下文),可以用一个简单的POJO豆加工的产品更新消息(豆结合可以帮助等)。然后,POJO豆将负责查询数据库中查找所有感兴趣的用户和使用发送电子邮件 camel-电子邮件
Then you can only need a single static route or a POJO consumer (see below) that can process the product update messages using a simple POJO bean (bean-binding can help, etc). The POJO bean would then be responsible for querying the database to find all "interested" users and send an email using camel-mail
public class NotificationBean {
@Consume(uri="activemq:topic:events.product.save")
public void onUpdate(@XPath("/object/id") String id,
@XPath("/object/rating") String rating) {
//query database for subscriptions for this product ID/rating, etc.
//for each interested subscriber
//send email (camel-mail, etc)
}
public void addSubscription(String productID, Integer rating, String email) {
//create/update subscription entry in database, etc...
}
}
这篇关于动态阿帕奇骆驼路线/背景设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!