이벤트 고객은 또한 비메시지 구동 Bean을 사용하여 작성할 수 있습니다.
// Get notification helper factory from JNDI InitialContext context = new InitialContext(); Object notificationHelperFactoryObject = context.lookup("com/ibm/events/NotificationHelperFactory"); NotificationHelperFactory nhFactory = (NotificationHelperFactory) PortableRemoteObject.narrow(notificationHelperFactoryObject, NotificationHelperFactory.class); // Create notification helper NotificationHelper notificationHelper = nhFactory.getNotificationHelper();
notificationHelper.setEventSelector("CommonBaseEvent[@severity > 30]");
각 이벤트 그룹은 단일 JMS 주제 및 임의의 수의 JMS 대기열과 연관될 수 있습니다. 공고 헬퍼를 조회하여 특정 이벤트 그룹과 연관된 목적지를 찾을 수 있습니다.
이벤트 그룹과 연관된 주제를 찾으려면, 이벤트 그룹 이름을 지정하는 NotificationHelper의 getJmsTopic(String) 메소드를 사용하십시오.MessagePort msgPort = notificationHelper.getJmsTopic("critical_events");이벤트 그룹과 연관된 대기열을 찾으려면, getJmsQueues(String) 메소드를 사용하십시오.
MessagePort[] msgPorts = notificationHelper.getJmsQueues("critical_events");리턴된 오브젝트는 JMS 주제를 나타내는 단일 MessagePort 오브젝트 또는 JMS 대기열을 나타내는 MessagePort 오브젝트의 배열입니다. MessagePort 인스턴스는 목적지 및 해당 연결 팩토리의 JNDI 이름을 포함하는 랩퍼 오브젝트입니다.
String connectionFactoryName = msgPort.getConnectionFactoryJndiName(); String destinationName = msgPort.getDestinationJndiName(); // create connection and session ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryName); Connection connection = connectionFactory.createConnection(); Session session = connection.createSesion(false, Session.CLIENT_ACKNOWLEDGE); // Create consumer and register listener Topic topic = (Topic) context.lookup(destinationName); MessageConsumer consumer = session.createConsumer(topic); consumer.setMessageListener(this); connection.start();
리스너의 onMessage() 메소드에서 공고 헬퍼를 사용하여 수신되는 각 JMS 메시지를 이벤트 공고를 포함하는 배열로 변환하십시오. (이벤트가 공고 헬퍼에 지정된 이벤트 선택자와 일치하지 않는 경우 배열은 비어 있습니다.) 이벤트 공고는 EventNotification 인터페이스를 구현하는 클래스의 인스턴스입니다.
public void onMessage(Message msg) { EventNotification[] notifications = notificationHelper.getEventNotifications(msg); // ...
공고 유형 | 설명 |
---|---|
CREATE_EVENT _NOTIFICATION_TYPE |
새 이벤트가 목적지와 연관된 이벤트 그룹에 작성되었습니다. 이는 새 이벤트가 전송되었거나 기존 이벤트가 변경되어 이제 이벤트 그룹 정의와 일치함을 의미합니다. 공고에는 또한 전체 이벤트 데이터가 들어있습니다. |
REMOVE_EVENT _NOTIFICATION_TYPE |
이벤트 데이터베이스에 저장된 이벤트는 목적지와 연관된 이벤트 그룹에서 제거되었습니다. 이는 이벤트가 이벤트 데이터베이스에서 삭제되었거나 기존 이벤트가 변경되어 더 이상 이벤트 그룹 정의와 일치하지 않음을 의미합니다. 공고에는 또한 삭제된 이벤트의 글로벌 인스턴스 ID가 들어있습니다. |
UPDATE_EVENT _NOTIFICATION_TYPE |
이벤트 데이터베이스에 저장된 이벤트가 목적지와 연관된 이벤트 그룹에서 이벤트의 멤버쉽을 변경하지 않는 방법으로 갱신되었습니다. 공고에는 또한 전체 이벤트 데이터가 들어있습니다. |
for (int i = 0; i < notifications.length; i++) { int notifType = notifications[i].getNotificationType(); if(notifType == NotificationHelper.CREATE_EVENT_NOTIFICATION_TYPE) { CommonBaseEvent event = notifications[i].getEvent(); if (event != null) { // process the new event // ... } } else if(notifType == NotificationHelper.UPDATE_EVENT_NOTIFICATION_TYPE) { CommonBaseEvent event = notifications[i].getEvent(); if (event != null) { // process the updated event // ... } } else if(notifType == NotificationHelper.REMOVE_EVENT_NOTIFICATION_TYPE) { String eventId = notifications.[i].getGlobalInstanceId(); // process the event deletion // ... } }
최종 갱신: Fri Jun 2 2006
(c) Copyright IBM Corporation 2005.
이 Information Center는 Eclipse 기술을 기반으로 합니다. (http://www.eclipse.org)