开发者

ActiveMQ messagedriven bean to JSF

开发者 https://www.devze.com 2023-01-08 07:39 出处:网络
I am currently reading from ActiveMQ with a Message driven bean (EJB3) in the back end. The problem I am facing is that I have to update a table in my JSF page as soon as I receive the message from Ac

I am currently reading from ActiveMQ with a Message driven bean (EJB3) in the back end. The problem I am facing is that I have to update a table in my JSF page as soon as I receive the message from ActiveMQ in the message driven bean.

Any suggestions of the technologies I can try woul开发者_Go百科d be great. I am currently using primefaces and glassfish.

Thx


You could use primefaces poll to periodically check if there are new messages

<h:form>  
     <p:dataTable id="msgTable" var="msg" value="#{tableBean.messages} ">
     ...
     </p:dataTable>

     <p:poll interval="3"   
             actionListener="#{mdBean.messagesAvailable}" update="msgTable" />  
</h:form> 

See http://97.107.138.40:8080/prime-showcase/ui/ajaxPollHome.jsf for more detail.


You cannot really call a (JSF) managed bean method directly from a message driven bean, since the scopes and times during which they are active are completely different.

The managed bean basically is active during an HTTP request. Afterwards its state might still be stored somewhere (i.e. if application, session or conversation scope is used), but it's not actively doing anything.

What you could do is use a technology like Comet, where you basically suspend the request from the backing bean. You can then let the backing bean wait for something before resuming the request again. You can let the managed bean listen to the same JMS queue that the message driven bean is listening to (assuming JMS is used), or you can let the managed bean listen to the CDI event bus. As soon as the MDB receives something from ActiveMQ, the MDB can put this on the CDI event bus and the backing bean will receive it.

In effect the MDB is then functioning as a bridge component.

There were a few presentations on Devoxx '10 that demonstrated something quite similar to what you are asking.

I think among others this presentation went into that stuff: http://www.adam-bien.com/roller/abien/entry/pets_and_aliens_running_on

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号