交易成功后如何发送XMPP消息?
在我的项目中,我将所有服务设计为无状态会话 bean。在工作流程中,会创建新数据并将其报告给客户。我只想在事务成功提交时发送此消息。
我注册了一个 ServletContextListener 来调度我的 xmpp 数据包(smack 库)。当我收到数据包时,我找到我的调度有状态会话 bean 并开始处理请求。
public void processPacket(Packet packet) {
try{
if(packet instanceof RawRequest){
DispatchIQService service = Core.lookup(DispatchIQService.class);
service.process(connection, (RawRequest)packet);
// sending of the messages should happen here, because transaction completed successful.
}else{
log.debug("Packet ignored: " + packet.toXML());
}
}catch(Exception e){
log.error(e, e);
}
}
如何在跨多个 bean 的工作流程中收集生成的消息?我将从调度 bean 返回此列表,然后发送消息。我的简单解决方案是通过一个列表进行路由,在其中添加消息,但是有没有更优雅的方法?
我有一个 XMPP 资源(名册 http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/Roster.html)我必须访问来自所有豆类。我怎样才能做到这一点?将其存储到静态变量中并同步对其的访问听起来不太好。
In my project I have all services designed as stateless session beans. During the workflow, new data is created and this should be reported back to the clients. I only want to send this messages when the transaction is successfully committed.
I have a ServletContextListener registered which dispatches my xmpp packets (smack library). When I receive a packet, I locate my dispatching stateful session bean and start the processing of the request.
public void processPacket(Packet packet) {
try{
if(packet instanceof RawRequest){
DispatchIQService service = Core.lookup(DispatchIQService.class);
service.process(connection, (RawRequest)packet);
// sending of the messages should happen here, because transaction completed successful.
}else{
log.debug("Packet ignored: " + packet.toXML());
}
}catch(Exception e){
log.error(e, e);
}
}
How can I collect this generated messages during the workflow accross multiple beans? I would return this list from the dispatch bean and send the messages afterwards. My simple solution would be to route through a list where I add my messages, but is there a more elegant way?
I have an XMPP resource (roster http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/smack/Roster.html) which I have to access from all beans. How can I accomplish that? Store it into a static variable and synchronize the access to it doesn't sound very good.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Markus,我不是 J2EE 专家,但为了您的目的,我建议您看一下 JMS。这将帮助您实施基于消息的方法。
对于我来说,我曾经使用 RabbitMQ 系统。这是很棒的体验,但需要额外的软件来运行系统。
Markus, I'm not a guru of J2EE, but for your purposes I recommend taking a look at JMS. This will help you implement message-based approach.
As for me, I used to go with RabbitMQ system. It was great experience, but additional software is required to run the system.