Using the event api to publish an event programmatically

Suppose your event is based on the below definition, namely the <process> element


<?xml version="1.0" encoding="UTF-8"?>
<schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="http://example.com/end2end_108_InvokingCompositeServices/HelloWorld_Sync"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="process">
<complexType>
<sequence>
<element name="input" type="string"/>
</sequence>
</complexType>
</element>
</schema>


and the event (InitiateHelloWorldEvent) itself is described with

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://schemas.oracle.com/events/edl" targetNamespace="http://schemas.oracle.com/events/edl/HelloWorldEvents">
<schema-import namespace="http://example.com/end2end_108_InvokingCompositeServices/HelloWorld_Sync" location="xsd/HelloWorld_Sync.xsd"/>
<event-definition name="InitiateHelloWorldEvent">
<content xmlns:ns0="http://example.com/end2end_108_InvokingCompositeServices/HelloWorld_Sync" element="ns0:process"/>
</event-definition>
</definitions>

here is how you can build and raise this event programmatically.

// load properties from file
Properties props = SampleUtils.loadPropertiesFromFile();

System.out.println("Creating datasource to db backed EDN");
// create a datasource programmatically from properties and a connect string
DataSource dataSource = SampleUtils.initDataSource(props);

System.out.println("Creating BusinessEventConnectionFactory...");
// next step, create an AQ based connection factory
BusinessEventConnectionFactory factory =
new SAQRemoteBusinessEventConnectionFactory(
dataSource, dataSource, null);
System.out.println("Creating bizEvent connection...");
// on top we need a biz event connection, that captures security, and a few other pieces
BusinessEventConnection conn =
factory.createBusinessEventConnection();
// next step, create the event, callout to sampleUtils
BusinessEvent businessEvent =
SampleUtils.buildEvent((String)getInput().getValue());

BusinessEventMediator mediator = new BusinessEventMediator();
// and publish it via connection
conn.publishEvent(businessEvent, 3);

The event can be created with the code below ..


public static BusinessEvent buildEvent(String input)
throws Exception
{
QName eventName =
new QName ("http://schemas.oracle.com/events/edl/HelloWorldEvents",
"InitiateHelloWorldEvent");
BusinessEventBuilder beb = BusinessEventBuilder.newInstance();
// set the event name (that matches the QName of the EDL)
beb.setEventName(eventName);
// payload element as dom
beb.setBody(createElementFromInput(input));
UUID uuid = UUID.randomUUID();
beb.setProperty(BusinessEvent.EVENT_ID, uuid);
// the conversation id can help to find the composite instance later via conv id.
beb.setProperty(BusinessEvent.PROPERTY_CONVERSATION_ID, uuid);
return beb.createEvent();
}

The sample utilities that are used in this post can be found here

Comments:

Hi Clemens As far as I know there is also a PL/SQL API for creating and raising Business Events. Do you have any pointer to the documentation of the PL/SQL API? Greetings from snowy Switzerland Guido

Posted by Anonymous on December 12, 2009 at 09:54 PM PST #

Hi, U have a nice post! It is so interesting and realistic ! Thanks for sharing !

Posted by foam koozie styles on December 14, 2009 at 02:53 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Tips and tricks straight from the SOA / BPM development team at Oracle HQ

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today