2

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.

4

1 回答 1

2

Markus,我不是 J2EE 的专家,但出于您的目的,我建议您看看JMS。这将帮助您实现基于消息的方法。至于我,我曾经使用 RabbitMQ 系统。这是一次很棒的体验,但运行系统需要额外的软件。

于 2011-09-06T08:07:25.943 回答