참조사이트 : http://docs.jboss.org/seam/1.1GA/reference/en/html/remoting.html
private void sendMessage(ErioEvent msg) {
TopicConnection conn = null;
TopicSession session = null;
Topic topic = null;
try {
서버딴에서 클라이언트로 메시지를 보내주고 싶을때 JBOSS의 JMS Topic 를 사용하면 됩니다.
JAVA
public void logOccurred(PLCLogEvent e) {
HashMap<String, Object> maps = new HashMap<String, Object>();
maps.put("msg", e.getMessage());
ErioEvent msg = new ErioEvent("PLC_Log", maps);
sendMessage(msg);
}
private void sendMessage(ErioEvent msg) {
TopicConnection conn = null;
TopicSession session = null;
Topic topic = null;
try {
Properties props = new Properties();
props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
props.setProperty("java.naming.provider.url", "localhost");
Context context = new InitialContext(props);
TopicConnectionFactory tcf = (TopicConnectionFactory) context.lookup("ConnectionFactory");
conn = tcf.createTopicConnection();
topic = (Topic) context.lookup("topic/Ticket");
session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
conn.start();
TopicPublisher send = session.createPublisher(topic);
ObjectMessage message = session.createObjectMessage(msg.getData());
send.publish(message);
send.close();
conn.close();
} catch (Exception e) {
trace(e.toString() + " Does the queue exist?");
}
}
xml
<mbean code="org.jboss.mq.server.jmx.Topic"
name="jboss.mq.destination:service=Topic,name=Ticket">
<depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
<depends optional-attribute-name="SecurityManager">jboss.mq:service=SecurityManager</depends>
<attribute name="SecurityConf">
<security>
<role name="guest" read="true" write="true"/>
<role name="publisher" read="true" write="true" create="true"/>
<role name="durpublisher" read="true" write="true" create="true"/>
</security>
</attribute>
</mbean>
javaScript
function subscribe(){
Seam.Remoting.displayLoadingMessage=function(){};
Seam.Remoting.hideLoadingMessage=function(){}; Seam.Remoting.subscribe("Ticket",callBack);
Seam.Remoting.displayLoadingMessage=function(){};
Seam.Remoting.hideLoadingMessage=function(){}; Seam.Remoting.subscribe("Ticket",callBack);
}
function callBack(message) {
if (message instanceof Seam.Remoting.TextMessage) {
Alert("Message Payload Containing - " + message.getText());
}
//processing 중이면 함수 종료..
else if (message instanceof Seam.Remoting.ObjectMessage) {
var object=message.getValue();
var msg=object.get("msg");
}else {
Alert("Message Payload Containing - " + payload.length());
}
}