Sample programs that can be used to demonstrate and test the firing of events on various transports.

# Samples

Overview

Setup

- Deployment
- Define User metadata
- Define StoredProcess metadata

Process Flow samples

- HelloWorld
- ProfitLoss
- ProductSales
- ProductSalesAlert

Application listener samples

- ListenerTest

## Overview

This package which is located in sas.svc.events.jar includes sample programs that send events to an EventBroker service for demonstration and testing purposes.

## Setup

### Deployment

Refer to this document for deployment details. A sample deployment file, deployment.xml, is included in this package. This Foundation Service deployment file can be imported into a SAS Metadata Repository using the Foundation Service Manager Plug-in component of the SAS Management Console.

If you will be using the StoredProcess samples, you must edit the InformationService repository definitions by editing the Host, Port, Domain, and Base definitions for each repository (omi, dav). For example the Sample repository should contain the following values: Host="host where the SAS Metadata Repository is running", Port="port where the SAS Metadata Repository is listening", Domain="authentication domain in which the SAS Metadata Repository is running". The webDAV repository should contain the following values: Host="host where the webDAV server is running", Port="port where the webDAV server is listening", Domain="authentication domain in which the webDAV server is running", Base="the webDAV base path". You must also edit the UserService global profile by specifying the appropriate Domain URL to designate where to store global profile information (most likely in the Sample omi repository).

### Define User metadata

Define users if events will be run under a security context. Refer to security considerations for more detail. This step is necessary if you will be using the StoredProcess samples.

Use the User Manager Plug-in component of the SAS Management Console to define new users.

### Define StoredProcess metadata

Before running the StoredProcess samples you will need to define a StoredProcess Server using the Server Manager Plug-in component of the SAS Management Console.

You will also need to define the individual StoredProcess samples using the Stored Process Manager Plug-in component of the SAS Management Console. You can use the LoadStoredProcessSamples.sas program to load the stored process samples. However, you still must fully configure these stored processes by associating them to the appropriate SAS StoredProcess Server and source directory.

## Process Flow samples

Process flows are one type of handling agent that can process events.

### HelloWorld

HelloWorld is a very simple request/response event. When this event is triggered at an event broker, it will invoke the HelloWorldFlow process flow. This process flow contains only one node that simply echos the incoming event properties and event body in the returned result.

To demonstrate the firing of this event, the following samples are provided:

- To send this event over HTTP to the event broker, open HelloWorld.htm in your favorite browser and press the Send Event button.

  This sample assumes that the broker is running on localhost and listening on port 8101 for HTTP requests.

### ProfitLoss

ProfitLoss is a more complex request/response event that demonstrates message manipulation and propagation. The idea behind this event is to analyze sales regions in a particular company to determine if the actual sales in a region exceeded the projected outcome. When this event is triggered at an event broker, it will invoke the ProfitLossFlow process flow. This process flow contains five processing nodes. The first node demonstrates the use of properties by obtaining the Company property from the event properties and using its value as the name of the company to analyze. This node will then create a new message that contains only a subset of information from the original message that pertains to the desired company to analyze and propagates this message to the next node in the flow. This next node will then determine the regions that are profitable and the regions that are not profitable. It will then create two messages: one message containing profitable regions and the other containing non-profitable regions. It will then propagate these messages to different nodes for further processing. ProfitLossFlowNode3 processing node will receive the message containing profitable regions. This node will create a new message that summarizes the profitable regions and their total profitability. This output message is then propagated to the final processing node, ProfitLossFlowNode5. Likewise, ProfitLossFlowNode4 processing node will receive the message containing regions with losses. This node will create a new message that summarizes the regions with losses and their total net loss. This output message is also propagated to the final processing node, ProfitLossFlowNode5. The final processing node will join the information it receives from its two input messages and send the result back to the event originator as the response.

To demonstrate the firing of this event, the following samples are provided:

- To send this event over HTTP to the event broker, open ProfitLoss.htm in your favorite browser and press the Send Event button.

  This sample assumes that the broker is running on localhost and listening on port 8101 for HTTP requests.

- To send this event using SOAP over HTTP, execute the com.sas.services.events.broker.samples.ProfitLossSOAP java program. This program uses ProfitLossEventBody.xml as the event body.

  This sample assumes that the broker is running on localhost and listening on port 8102 for HTTP-SOAP requests.

- To send this event over HTTP using JavaBeans and JSP running in a Web Server container, open BrokerUsingBean.htm in your favorite browser and press the Send Event button to invoke BrokerConnection.jsp JSP. This JSP will use com.sas.services.events.broker.samples.HttpBean JavaBean to send the actual event and receive its response so it most also be made available in the Web Server container environment.

  This sample assumes that the Web Server is running on localhost and listening on port 8080 and that the broker is running on localhost and listening on port 8101.

- To send this event using JMS, use the com.sas.services.events.broker.samples.ProfitLossJMS java program. This program uses ProfitLossEventBody.xml as the event body. This program uses the JMS.properties file to determine how to establish a connection and send an event to the message subsystem whether it be using JNDI lookup (provider-independent) or provider-dependent using either WebsphereMQ or SunONEMQ. This file is initially setup to send events to a WebsphereMQ messaging system (host=localhost, port=1414, channel=JAVA.CHANNEL, queue=LOCAL, replyToQueue=RESPQ).

  This sample assumes that a WebsphereMQ messaging system in running on localhost and has a QueueManager listening on port 1414. It also assumes that a Server Connection by the name of JAVA.CHANNEL and queues by the name of LOCAL and RESPQ queue have been defined under this same QueueManager. You can change any of these parameters by modifying the JMS.properties file. You will also need to modify the event broker configuration for this MQJMS transport as well by using the Foundation Service Manager Plug-in.

  You can use the com.sas.services.events.broker.samples.ReceiveJMSReply java program to fetch the event broker's reply off of the replyToQueue.

  You should refer to your JMS-provider's documentation for setting up and configuring your message subsystem.

### ProductSales

ProductSales is a stored process request/response event. When this event is triggered at an event broker, it will invoke the ProductSalesFlow process flow. This process flow contains a single node, ExecuteSPNode, that invokes the productsales.sas stored process on the designated SAS StoredProcess Server. The input to this stored process is the name of the country and year that you are interested in analyzing. The resulting dataset is the response that is sent to the event orginator.

The ExecuteSPNode processing node must be run under a security context. Therefore, appropriate credentials must be passed with the event so that they may be authenticated and used as the security context.

To demonstrate the firing of this event, the following samples are provided:

- To send this event over HTTP to the event broker, open ProductSales.htm in your favorite browser and press the Send Event button.

  This sample assumes that the broker is running on localhost and listening on port 8101 for HTTP requests. It also assumes that the SAS Metadata Server and the SAS StoredProcess Server are up and running on their appropriate machines.

### ProductSalesAlert

ProductSalesAlert is another stored process request/response event. When this event is triggered at the event broker, it will invoke the ProductSalesAlertFlow process flow. This process flow contains a single node, ExecuteSPAlertNode, that invokes the productsales.sas stored process on the designated SAS StoredProcess Server. The input to this stored process is the name of the country and year that you are interested in analyzing. The resulting dataset is published to the designated webDAV server and an alert detailing this process is sent to the event originator.

The ExecuteSPAlertNode processing node must be run under a security context. Therefore, appropriate credentials must be passed with the event so that they may be authenticated and used as the security context.

To demonstrate the firing of this event, the following samples are provided:

- To send this event over HTTP to the event broker, open ProductSalesAlert.htm in your favorite browser and press submit.

  This sample assumes that the broker is running on localhost and listening on port 8101 for HTTP requests. It also assumes that the SAS Metadata Server, the SAS StoredProcess Server, and the webDAV server are up and running on their appropriate machines.

## Application listener samples

Application listeners are one type of handling agent that can process events.

### ListenerTest

Start com.sas.services.events.broker.samples.ListenerTest java program to listen for incoming ListenerTest events. This program assumes that an event broker has been deployed as a remoteable service such that it has bound itself to an RMI Registry at the following address: //localhost:1099/com.sas.services.events.broker.EventBrokerService. When this event is triggered at the event broker, it will invoke this listener. This listener will simply reply with the following response if everything works as expected: <ListenerTest>Test was successful.</ListenerTest>

To demonstrate the firing of this event, the following samples are provided:

- To send this event over HTTP to the event broker, open ListenerTest.htm in your favorite browser and press the Send Event button.

  This sample assumes that the broker is running on localhost and listening on port 8101 for HTTP requests and the com.sas.services.events.broker.samples.ListenerTest java program is running and has registered itself to the broker as a listener for ListenerTest request/response events.