public final class SampleEventProducer extends Object
The code below illustrates how an event producer publishes an event. A producer publishes events without knowledge of which consumers will be notified of the event; it doesn't even know if there are even any consumers to receive the event.
For events to be successfully passed from a producer to a consumer, the producer and consumer must merely have a common understanding of the event definition. The definition includes the event identity, specified by a family and event type. An event body allows an arbitrary set of data to be included with the event. There are virtually no restrictions on the structure of the data in the event body, but it is commonly structured as JSON or XML.
Additional metadata may be provided by the publisher to allow a consumer to "filter out" events in which it has no interest. For example, consumers A and B may both periodically request services from producer P. The requests may take a significant amount of time to fulfill, and P publishes an event to notify consumers when the request has been fulfilled. During the initial request a consumer and P agree upon a correlation ID that can be later used to match an event to a request. A and B then can create subscriptions for the event and include the correlation ID as part of the subscription filter. Then, when P publishes the event, it includes the correlation ID as metadata so that events are delivered only to the consumer who has subscribed with that correlation ID.
In the example below, the EventingFactory
is first called to create
an EventMetaData
object. This object is filled with any desired data
that is relevant to the event being published. Then, the event body is
constructed and an arbitrary event version is specified. Finally an
EventProducer
object is created with an event family name and event
family type. The publish method on the producer object causes the
event to be delivered to any consumers that have subscribed to receive the
event.
package com.mycompany; import com.avaya.collaboration.eventing.EventMetaData; import com.avaya.collaboration.eventing.EventProducer; import com.avaya.collaboration.eventing.EventingFactory; import com.avaya.collaboration.eventing.families.EventFamilyCall; final EventMetaData filterData = EventingFactory.createEventMetaData(); filterData.addValue(EventFamilyCall.FILTER_UCID, "someCallId"); filterData.getValueMap().put(EventFamilyCall.FILTER_UCID, "someUcid"); // alternative filterData.setCorrelationId("someCorrelationId"); filterData.setUser("+13035383530@avaya.com"); final String eventBody = "this is some payload"; final String eventVersion = "1.0.0.0"; final EventProducer publisher = EventingFactory.createEventProducer(EventFamilyCall.FAMILY_NAME, EventFamilyCall.EVENT_CALL_OFFERED_FROM_CALLING_PARTY, filterData, eventBody, eventVersion); publisher.publish();
Copyright © 2023 Avaya. All rights reserved.