Sun Java System Message Queue 4.1 版本說明

建立事件偵聽程式

下列程式碼範例描述設定連線事件偵聽程式的方式。每次發生連線事件時,用戶端執行階段便會呼叫事件偵聽程式的 onEvent 方法。

//create an MQ connection factory.

com.sun.messaging.ConnectionFactory factory =
        new com.sun.messaging.ConnectionFactory();

//create an MQ connection.

com.sun.messaging.jms.Connection connection = 
       (com.sun.messaging.jms.Connection )factory.createConnection();

//construct an MQ event listener.  The listener implements 
//com.sun.messaging.jms.notification.EventListener interface.

com.sun.messaging.jms.notification.EventListener eListener = 
       new ApplicationEventListener();

//set event listener to the MQ connection.

connection.setEventListener ( eListener );