交易成功后如何发送XMPP消息?

发布于 2024-12-03 06:31:08 字数 1102 浏览 0 评论 0原文

在我的项目中,我将所有服务设计为无状态会话 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);
    }
}
  1. 如何在跨多个 bean 的工作流程中收集生成的消息?我将从调度 bean 返回此列表,然后发送消息。我的简单解决方案是通过一个列表进行路由,在其中添加消息,但是有没有更优雅的方法?

  2. 我有一个 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);
    }
}
  1. 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?

  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时常饿 2024-12-10 06:31:08

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文