When
an application is configured to use the Web messaging service, there
are multiple ways to publish information to browser clients. Browser
client publishing and publishing through a Web application are discussed
in this topic.
The first method is client publishing through the browser. Publishing is part of the Bayeux protocol. Publishing from the browser enables a different style of Web application. Some examples can be embedding chat and presence into a Web page, a collaborative Web editing application, or game application. The clientCanPublish option must be set to
truein the Web messaging configuration file to allow client publishing. The code to publish within the browser is similar to the following Dojo toolkit cometd client example:
dojox.cometd.publish("/testtopic", { test: "data"}); |
The second method is publishing to Web messaging clients through a JavaTM Platform, Enterprise Edition (Java EE) application. The Web messaging service bridges clients to the service integration bus for message publishing and delivery. Messages that need to be sent to Web clients must be routed through a service integration bus. Standard J2EE service integration bus publishing methods should be used. These standard methods can be used in an enterprise bean or servlet. Refer to the service integration bus publishing section for additional information..
To assist in publishing to Web messaging clients, a publishing API is provided in the Web messaging application utility library. Publishing to a Web messaging client is simplified when using the publishing API as opposed to standard JMS publishing methods. These simplifications include Bayeux channel-to-service integration topic mapping and easy identification of supported JMS message types. Use the following steps when using the publishing API:
<servlet> <display-name>Publisher</display-name> <servlet-name>Publisher</servlet-name> <servlet-class> com.ibm.websphere.webmsg.publisher.jndijms.JmsPublisherServlet </servlet-class> <init-param> <param-name>CONNECTION_FACTORY_JNDI_NAME</param-name> <param-value>java:comp/env/jms/QuotePublish</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> |
Publisher publisher = (Publisher)servletContext.getAttribute(JmsPublisherServlet.PUBLISHER_SERVLET_CONTEXT_KEY); if (publisher == null) { throw new ServletException("Publisher servlet not initialized, or not initialized before app"); } try { publisher.publish(new BayeuxJmsTextMsg(s.getTopic(), data)); } catch (PublisherException e){ logger.log(Level.WARNING, "Error publishing simulated data. Msg: " + e.toString()); } |
For example usage of the Publishing API, refer to the QuoteStreamer application. Read the Publishing API documentation for the Web messaging publishing API.