You are on page 1of 19

Corent Technology Pvt. Ltd..

Technical Paper
Getting Started With Mule + ActiveMQ + jBPM

09/05/2012 Version: 1.0

This Technical Paper describes the features of Mule and the configuration of Mule with ActiveMQ and jBPM.

Revision History Table - Revision Status lists the latest version and date for the various sections of the specification. Versions 0.X are prerelease draft versions. Versions 1.X to X.X are post release versions. The number to the left of the decimal in the version number indicates the major version number. The number to the right of the decimal in the version number indicates the minor version number. The major version number will change for the following reasons: Information added to document. Information removed from document. Rearrangement of sections in the document. Revisions to the scope or purpose of the document. The minor version number will change for the following reasons: Spelling corrections. Page layout or formatting corrections. Minor changes that do not affect the scope or purpose of the document.
Version 1.0 Date 09/05/12 Initial release Description

Table 0 Revision Status

Table of Contents
1 Introduction.................................................................................................................................................................5 2 Overview......................................................................................................................................................................6 3 Creating the SQL Historian........................................................................................................................................8

3.1 IMPLEMENTATION OF A HISTORIAN SQL TABLE...............................................................................................8 3.2 CONFIGURATION OF THE HISTORIAN IN PA....................................................................................................8
4 Creating Local Result Set Tables........................................................................................................................10 5 Creating 601 Models in PA......................................................................................................................................11 6 Controls and Statements within RTIP....................................................................................................................13

6.1 DEFINE RTIP CONTROLS.......................................................................................................................13 6.1.1 Production Unit..............................................................................................................................13 6.1.2 Production Line ............................................................................................................................13 6.1.3 Department ..................................................................................................................................13 6.1.4 Batch Number...............................................................................................................................14 6.2 CREATE STATEMENT..............................................................................................................................14

1 What is Mule ESB?


Mule ESB is a lightweight Java-based enterprise service bus (ESB) and integration platform that allows developers to connect applications together quickly and easily, enabling them to exchange data. Mule ESB enables easy integration of existing systems, regardless of the different technologies that the applications use, including JMS, Web Services, JDBC, HTTP, and more.

Service creation and hosting expose and host reusable services, using Mule ESB as a lightweight service container Service mediation shield services from message formats and protocols, separate business logic from messaging, and enable location-independent service calls Message routing route, filter, aggregate, and re-sequence messages based on content and rules Data transformation exchange data across varying formats and transport protocols

2 To ESB or not to ESB.


1. Are you integrating 3 or more applications/services? 2. Will you need to plug in more applications in the future? 3. Do you need to use more than one type of communication protocol? 4. Do you need message routing capabilities such as forking and aggregating message flows, or content-based routing? 5. Do you need to publish services for consumption by other applications?

3 Creating the SQL Historian


The configuration of the SQL Historian is build up by two parts: Implementation of a SQL table for the tags and their values Configuration of the Historian in PA

Implementation of a Historian SQL table


The table can be created executing the following script.

SQL Historian.zip

Configuration of the Historian in PA


Select SQL Server as the Historian Type requires a number of option values to be set. The option values can be set as (please insert the IP address of the server instead of XXX for the Connection String): BrowseSQL Connection String DeleteSQL ExecDirectFlag InsertSQL ReadAfterSQL Select convert(varchar(20),Tag_Id) as TagID, sDescription, sEngUnits, 'Float' from Local_SQLHistorian where convert(varchar(20),Tag_Id) like ? TagId DRIVER={SQL Server}; Server=XXX;Database=GBDB;UID=sa;PWD=sa Delete from Local_SQLHistorian where tTimeStamp = ?TimeStamp and Tag_Id = convert(int,?TagId) and IMilisecond is null False Set RowCount ?NumValues; Select tTimestamp, value = case when sValue is null then convert(varchar(20), dValue) else sValue end, status = case when dQuality = 0 then 'Good' else 'Bad' end from Local_SQLHistorian where Tag_Id = convert(int,?TagId) and tTimeStamp > ?TimeStamp order by tTimeStamp Set RowCount ?NumValues; Select tTimestamp, value = case when sValue is null then convert(varchar(20), dValue) else sValue end, status = case when dQuality = 0 then 'Good' else 'Bad' end from Local_SQLHistorian where Tag_Id = convert(int,?TagId) and tTimeStamp < ?TimeStamp order by tTimeStamp desc Set RowCount ?NumValues; Select tTimestamp, value = case when sValue is null then convert(varchar(20), dValue) else sValue end, status = case when dQuality = 0 then 'Good' else 'Bad' end from Local_SQLHistorian where Tag_Id = convert(int,?TagId) and tTimeStamp > ?StartTime and tTimeStamp < ?EndTime order by tTimeStamp Select getdate() as CurTime

ReadBeforeSQL

ReadBetweenSQL

TimeSQL

More information about SQL Historian can be found in the Proficy Plant Applications Administrator Documentation. The Tag-Ids is the number of the Result Set Example: A value change for the tag with Tag-Id equals 1 will activate the 601 model for the Production Event. Remark that it is needed to fill in a tag value for each tag in the SQL Historian before the tag can be seen from a browse tag window in PA administrator. The scripts in Insert Tag Values zip file can be used to insert the first values for Production Events, Variable Values, Grade Change, Downtime Events, User Defined Events, Waste Events and Production Plan.

Insert Tag Values.zip

4 Creating Local Result Set Tables


The local Result Set tables is following the structure of the Result Set for the Event and are all called Local_RTIPXXX, where XXX is the Event type. Each local Result Set table includes a last column with the header Flag. This is used by the 601 Model stored procedure to indicate and delete processed rows. The zip-file below includes the local Result Set tables for Production Events, Variable Values, Grade Change, Downtime Events, User Defined Events, Waste Events and Production Plan.

Local Result Set Tables.zip

5 Creating 601 Models in PA


The 601 models can be imported from Administer Models in the Global Configuration folder in the Proficy Plant Applications Administrator, using the files included in the zip-file below. The model number for the different models is 1000XX where XX is the Result Set Number (Example: 100001 is the model number of the 601 model used for Production Events).

601 Models.zip

The different models are triggering a stored procedure when a value change occurs for a specific tag in the SQL Historian. The stored procedure follows the structure below (this example is using the Production Event. The Local_RTIPProductionEvents is the local Result Set table and the Local_SQLHistorian is the SQL Historian table): CREATE Procedure spLocal_TriggerRTIPProductionEvents @ReturnStatus int OUTPUT, @ReturnMessage varchar(255) OUTPUT, @EC_Id int, @TriggerTimestamp datetime AS Declare @MaxTimeStamp DateTime -- In case a end-user inserts a new row during the execution of this SP Update Local_RTIPProductionEvents Set Flag = 1 Where Flag = 0 -- Select * from local Result Set table Select 1, Id, Transaction_Type, Event_Id, Event_Num, PU_Id, Convert(VarChar(30),TimeStamp,120), Applied_Product, Source_Event, Event_Status, Confirmed, User_Id, Post_Update, Conformance, TestPctComplete, StartTime, TransNum, TestingStatus, CommentId, EventSubTypeId, EntryOn, ApprovedUserId, SecondUserId, ApprovedReasonId, UserReasonId, UserSignOffId, ExtendedInfo From Local_RTIPProductionEvents Where Flag = 1 -- Deletes processed rows from the local Result Set table Delete From Local_RTIPProductionEvents Where Flag = 1 -- Set @MaxTimeStamp to the latest time where the specific tag in the SQL Historian was changed Select @MaxTimeStamp = Max(tTimeStamp) From Local_SQLHistorian Where Tag_Id = 1 -- Delete all tag changes from the SQL Historian but the last Delete From Local_SQLHistorian Where Tag_Id = 1 and tTimeStamp <> @MaxTimeStamp The zip file below includes the stored procedures for Production Events, Variable Values, Grade Change, Downtime Events, User Defined Events, Waste Events and Production Plan. These scripts need to be executed within a SQL Query Analyzer.

601 SPs.zip

The model has to be set up at any production unit in the Plant Model (one unit could be created only for this purpose). The models can be configured importing the Excel sheet below. Remember to substitute the Production Line, Production Unit, Event Subtype and name of the SQL Historian.

Configure Models.zip

Activate the models in the Proficy Plant Applications Administrator. Navigate to the unit where the Models have been attached. Select Configure Events, select the Configure Event Detection Models and active the models one-by-one.

6 Controls and Statements within RTIP


The following will focus on the left side of figure 1 the RTIP side. There are 3 steps that need to be fulfilled on the RTIP side in order to create PA Events from within RTIP. These are: 1. Define RTIP controls that should be used as inputs for the PA Event (examples: start time, production event number, process order number, reasons ) 2. Create Statement used to insert data into the local Result Set table and update the SQL Historian table 3. Create link between the RTIP controls and the Statement

Define RTIP Controls


The following example will create a batch on a specific unit. The input that should be given is the production unit and Batch Number the time when it is created in RTIP will be the time attached to the Batch. The Production Unit can be selected using the Plant Applications Collector within RTIP. In this example the enduser should first select Department, then Production Line and finally the Production Unit.

Production Unit
1. 2. 3. 4. 5. The Production Unit control has been dragged from the system tree (see figure The Object Type has been selected as a combo box Both Unit Description and Unit Id columns has been displayed Selected Item Column is Unit Description Selected Value Column is Unit Id

Production Line
1. 2. 3. 4. 5. 6. The Production Line control has been dragged from the system tree The Object Type has been selected as a combo box Both Line Description and Line Id columns has been displayed Selected Item Column is Line Description Selected Value Column is Line Id The Select Value Property has been linked to the Line Id of the Production Unit control

Department
1. 2. 3. 4. 5. 6. The Department control has been dragged from the system tree The Object Type has been selected as a combo box Both Department Description and Department Id columns has been displayed Selected Item Column is Department Description Selected Value Column is Department Id The Select Value Property has been linked to the Department Id of the Production Line control

Figure 1

Batch Number
1. Add a textbox for the Batch Number input

Figure 2

Create Statement
The only task for the statement used from RTIP to Create, Update or Delete an event in PA is to insert the parameter values into the local Result Set table. This is done using a Call statement, executing a stored procedure. The Call statement will include input values coming from the end-user selections (in our example this will be the Production Unit Id and Batch Number). These input values can now be used directly as parameter values into the local Result Set table or used to derive other parameter values. In our example the stored procedure looks as follows: CREATE PROCEDURE spLocal_InsertBatch @BatchNum VarChar(25), @PUId Int AS

Declare @Max int, @BatchExist int, @Timestamp VarChar(30), @Event_Id int -- If no Batch Number has not been transferred to the SP, error message and return If @BatchNum is Null Begin Select 'No Batch Number' as Message Return End -- If no Production Unit has not been transferred to the SP, error message and return If @PUId is Null Begin Select 'No Production Unit' as Message Return End -- Does the Batch already exist in the PA database Select @BatchExist = Count(*) From Events where Event_Num = @BatchNum and PU_Id = @PUId -- Create the batch if it does not exist in the PA database If @BatchExist = 0 Begin Select @Timestamp = Convert(VarChar(30),GetDate(),120) -- Hot insert, inserts the Batch directly in the database Execute spServer_DBMgrUpdEvent @Event_Id OUTPUT, @BatchNum, @PUId, @Timestamp, Null, Null, 26, 1, 0, 6, Null, Null, Null, Null, Null, 0 --Send insert to bus (post = 1, Pre = 0) -- Sends the Batch to the client (Post_Update = 1) Insert into Local_RTIPProductionEvents (Id, Transaction_Type, Event_Id, Event_Num, PU_Id, TimeStamp, Applied_Product, Source_Event, Event_Status, Confirmed, User_Id, Post_Update, Conformance, TestPctComplete, StartTime, TransNum, TestingStatus, CommentId, EventSubTypeId, EntryOn, ApprovedUserId, SecondUserId, ApprovedReasonId, UserReasonId, UserSignOffId, ExtendedInfo, Flag) Values(1,1,@Event_Id,@BatchNum,@PUId,@Timestamp,Null, Null, 5, Null, 8, 1, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, Null, 0) -- Increment the tag value for the Production Event tag Select @Max = Max(dValue) From Local_SQLHistorian Where Tag_Id = '1' Insert into Local_SQLHistorian (Tag_Id, sDescription, sEngUnits, Float, tTimeStamp, sValue, dValue, dQuality) Values('1','Production Events',Null, Null, Getdate(),Null,@Max+1,0) End -- If the Batch already exists, send error message and return If @BatchExist <> 0 Begin Select 'Batch already exists' as Message Return End -- Send success message Select 'Success Updating: ' + @BatchNum as Message This script needs to be executed in a SQL Query Analyzer and can be found in the zip-file below:

Insert Batch.zip

Before using the stored procedure in a Call statement it has to be included in a Schema (see RTIP documentation for how to create Schemas). Select the Schema where you want to include the stored procedure in the SQL Statement Builder, right click and select Add Table etc..

Figure 3 Select that the Schema contains Procedures. Click Next >.

Figure 4 Select the stored procedures that should be added to the Schema. Click Next > and Finish, and the stored procedure are now included. Select New Statement in the SQL Statement Builder and select Call as the type of SQL statement. Hereafter drag the stored procedure from the Schema folder into the empty Table Diagram frame.

Figure 5 Save the Statement and give it a name. RTIP has already built the Statement in the SQL Statement frame, and has selected names for the input parameters (par0_@BatchNum and par1_@PUId). RTIP concludes these input parameters by looking at the header of the stored procedure, but it is needed to execute the stored procedure from inside RTIP for RTIP to know what type of output it should expect. Execute Statement will prompt for values for the input parameters.

Figure 6 Click OK.

Figure 7 The result frame displays the output of the stored procedure (Message: Success Updating: ABC002). Return to the configure mode of the display with the input parameter, select the Data Source tab in the System Tree and drag the Statement just created into the display. Select the Object Type as Text Box and select to display the message column.

Figure 8

Select the Production Unit Combo Box and link the Selected Value property to the Message Text Box par1_@PUId.

Figure 9 Select the Batch Number Text Box and link the Text property to the Message Text Box par0_@BatchNum.

Figure 10

Now the two input values are linked to the input parameter of the statement. The last thing is a button to execute the statement. Insert the button and link the control to the Text Box Insert Batch (the Message Text Box).

Figure 11 Thats it. Now change the display to Run Mode and Select Department, Production Line, Production Unit and Insert Batch Number and Click on the Create Batch button to create a new Batch within the Proficy Plant Applications Database.

Figure 12

You might also like