+ All Categories
Home > Documents > OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

Date post: 27-Dec-2015
Category:
Upload: kory-oliver
View: 292 times
Download: 1 times
Share this document with a friend
60
OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser
Transcript
Page 1: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

OpenEdge® SQL & SonicMQ®:Using JMS with SQL Applications

Pat Bonser

Page 2: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

2 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Session Goals

Learn how to use JMS techniques – With a JDBC application– With an ODBC application– Using SQL java stored procedure– Using SQL java row trigger

Page 3: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

3 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL and SonicMQ

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions

Page 4: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

4 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – Supplier and Retailer

SonicMQBroker

Retailer Java™ App

Retailer Java AppOE SQL DB

Supplier Java App

(sports equipment vendor)

Java trigger

JDBC driver

JMS

Adding New product

Changing product’s price

Browsing orders

JMS

Placing orders

Show new product

Show price changes

JMS

JMS

Page 5: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

5 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Messaging

A mechanism enabling autonomous applications to communicate

Messages are units of information composed of– Body– Header

Destinations Priority Ordering Expiration Time-to-Live And more …

Page 6: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

6 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

JMS

A specification for Message-Oriented Middleware (MOM) provider – Version 1.1

A Java interface and semantics for inter-application messaging– Basic functionality of JMS

– Javax.jms.* package Enterprise Application Integration (EAI) http://java.sun.com/products/jms

Page 7: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

7 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

JMS Features

Standard client API Asynchronous or synchronous guaranteed

message delivery Transactions Message filtering Reliability levels Two messaging models with a common

interface

Page 8: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

8 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Basic JMS Terminology

ConnectionSession

Application A

Producer

Application B

Consumer

JMS - Message Oriented Middleware

Destination

Page 9: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

9 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

JMS Two Messaging Models

Point to Point (1 to 1)

Publish and Subscribe (1 to Many)

QueueSenderPotential Receiver

TopicPublisherSubscriber

Subscriber

Potential Receiver

Page 10: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

10 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Development of JMS

Develop the JMS client application Develop the JMS adapter Develop the producers and consumers Develop the interaction with the JMS server

Page 11: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

11 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

SonicMQ

A JMS provider Uses standard JMS components and terminology Extends the JMS specification

– Additional message types (XML, Multi-part, Large)– Distributed transactions (JTA XAResource API)– Security (authentication, authorization, SSL)– Open database connectivity– Continuous availability (Fault tolerant client

connection)

http://www.sonicsoftware.com

Page 12: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

12 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Install SonicMQ

Download the product from http://www.sonicsoftware.com

Typical installation components– A domain manager container

– The Sonic management console (SMC)

– The client runtime

– The default PSE pro database

– JRE ( Windows only )

Page 13: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

13 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Configuring and Managing SonicMQ

Sonic Management Console (SMC)– Create a new container hosting a broker

– View existing queues

– Create a new queue

– Monitor broker notification

Page 14: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

14 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Start the SonicMQ Domain

DomainContainer1 Broker1

QueueTopic

Start →Programs →Sonic Software →SonicMQ →SonicMQ Container1

Agent

ManagerDirectory

Service

Page 15: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

15 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

SonicMQ API and Archives

Packages– Javax.jms (standard JMS)

– Progress.message.jclient (Sonic extensions)– Progress.message.jclient.channel– Progress.message.jclient.xa

Archives– Under sonicmq-install-dir\lib\*.jar

Page 16: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

16 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL and SonicMQ

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions

Page 17: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

17 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL

SQL standard database open access via JDBC and ODBC

DataDirect JDBC driver– Core JDBC 2.0 and extensions

DataDirect ODBC driver– Core ODBC 3.0

Server integration with Java– Java Stored procedure and row trigger

Page 18: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

18 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL client-server architecture

Windows App

ODBC driverJDBC driver

Database Storage Manager

OE SQL ServerJVM

Java

sp/trigger

Java App

OpenEdge SQL

Database

Page 19: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

19 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Install OpenEdge SQL

SQL server – Choose the database component

– _sqlsrv2

– Multithreaded and reusable DataDirect JDBC and ODBC drivers

– Choose “SQL Client access”

– Java classes

– DLL or shared libraries

Page 20: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

20 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

JDBC application program initialization

Environment– CLASSPATH– Shared library path

Include the package– Import java.sql.*;

Load the driver– Class.forName(“com.progress.sql.jdbc.JdbcProgressDriver”);

Get the connection– DriverManager.getConnection()

– jdbc:jdbcprogress:T:host-name:port #:database-name Turn on the JDBC tracing

– DriverManager.setLogStream(PrintStream log)

Page 21: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

21 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Basic JDBC API

DriverManager

<Interface>Driver

<Interface>PreparedStatement

<Interface>Connection

<Interface>Statement

<Interface>ResultSet

<Interface>CallableStatement

<Interface>DatabaseMetaData

<Interface>ResultSetMetaData

Page 22: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

22 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

ODBC application program initialization

Setting the Shared library path Creating a DSN

– “Data Source (ODBC)” on Windows– “ODBC.INI” file on Unix

Allocate An Environment Handle– SQLAllocHandle(SQL_HANDLE_ENV,

SQL_NULL_HANDLE,&EnvHandle) Allocate A Connection Handle

– SQLAllocHandle(SQL_HANDLE_DBC, EnvHandle, &ConHandle)

Connect with the DSN– SQLConnect(ConHandle,…)

Page 23: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

23 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

ODBC APIs

The various ODBC functions can be broken down into seven distinct groups– Connections

– Cursors

– Executing SQL statements

– Receiving results

– Cancelling an operation

– Error handling

– Transaction control

Page 24: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

24 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Java Stored Procedures

Java snippets– All standard JAVA features– OpenEdge SQL-supplied JAVA classes

Integration between SQL and JAVA Enhances application

– Flexibility, Performance, Portability and reusability Extend SQL capabilities of databases

– Receive or send IN/OUT/INOUT parameters– Handle exceptions– Allow any SQL statement to access database– Return result set– Call other procedures– Use predefined and external JAVA classes

Page 25: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

25 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Java Stored Procedures (Cont.)

Transaction– Same as and part of the calling application– COMMIT or ROLLBACK statement not allowed

Security– Creation

RESOURCE or DBA privilege– Drop and Grant

DBA or the owner– Execution

DBA, owner or user who is granted with the EXECUTE– Only owner’s privileges checked for procedure objects

(tables, columns and etc) during execution

Page 26: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

26 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Working with Java Stored Procedures

Configuring– JDK, JRE and “sql_env” script

Using SQL statements– CREATE PROCEDURE– DROP PROCEDURE– CALL

Viewing– SYSPROGRESS.SYSPROCEDURES– SYSPROGRESS.SYSPROCTEXT

Exporting– SQLSCHEMA -P

Page 27: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

27 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Accessing Stored Procedures from Applications

Embed the call escape sequence { CALL proc_name [ ( parameter [ , ... ] ) ] }

JDBC “CallableStatement”

ODBC “SQLPrepare” or “SQLExecDirect”

try{CallableStatement statement;int Part_num = 318;statement = conn.prepareCall("{call order_parts(?)}");statement.setInt(1, Part_num);statement.execute();}

SQLUINTEGER Part_num;SQLINTEGER Part_numInd = 0;SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT,SQL_C_SLONG, SQL_INTEGER,0, 0, &Part_num, 0, Part_numInd);Part_num = 318;SQLExecDirect(hstmt, "{ call order_parts(?) } ", SQL_NTS);

Page 28: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

28 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Java row triggers

A special type of stored procedure To maintain database integrity Automatically invoked (“fired”) by certain

SQL operations OLDROW and NEWROW object

– getValue(), setValue() CREATE/DROP TRIGGER SQL statements SYSPROGRESS.SYSTRIGGER

Page 29: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

29 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL JAVA classes

execute

Open

close

fetch

wasNull

getValue

Found

getParam

SQLIStatement

SQLCursor

SQLPStatement

DhSQLResultSet

DhSQLException

setParam

makeNull

execute

rowCount

set

makeNull

insert

getDiagnostics

log

err

Page 30: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

30 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL and SonicMQ

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions

Page 31: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

31 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

JMS JMS

OpenEdge Database

EISJava/

J2EE™ Application

Legacy Application

JMSJMS

Message Broker ( SonicMQ )

JMSJMSCustomer Adapter

Customer Adapter

Customer Adapter

Customer Adapter

OpenEdge®Application

SonicMQ Messaging

Connection

Session

Producer or

Consumer

Page 32: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

32 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Solutions

Developing the JMS enabled client applications– JDBC + JMS

Developing the JMS adapter – JAVA class

– Java stored procedure Developing the JMS producer with the

database Java row triggers

Page 33: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

33 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Writing a JMS Adapter

Set the CLASSPATH Choose the messaging model

– PTP

– PUB/SUB Identify the role

– Producer

– Consumer Prepare message types

Page 34: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

34 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Include SonicMQ jars

CLASSPATH needs to include:– sonic_Client.jar

– mfcontext.jar

– gnu-regexp-1.0.6.jar

– jaxp.jar

– xercesImpl.jar

– xmlParserAPIs.jar

Page 35: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

35 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

PTP - Basic Steps

1. Initialization - Connect to a SonicMQ Broker

- Create a Session

- Create or lookup queues

2. Create a Message Producer/Consumer

3. Prepare Messages

4. Send/Receive Message

5. Close Message Producer/Consumer

Page 36: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

36 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Pub\Sub - Basic Steps

1. Initialization - Connect to a SonicMQ broker

- Create a Session

- Create or lookup Topics

2. Create a message publisher

3. Subscribe to Topic

4. Publish message to Topic

5. Consume message from a Topic

6. Close Message Producer/Consumer

Page 37: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

37 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Writing a JMS Adapter – InitializationString broker = "localhost:2506";//default sonic broker

String username = "wang"; //default user name

String password = "password";//default user password

// Create a SonicMQ connection.

Try

{

javax.jms.ConnectionFactory factory;

factory = (new progress.message.jclient.ConnectionFactory (broker));

javax.jms.Connect connect;

connect = factory.createConnection (username, password);

javax.jms.Session session;

session = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);

}

catch (javax.jms.JMSException jmse)

{

jmse.printStackTrace();

System.exit(1);

}

ConectionFactory

Session

Connection

Creates Creates

Creates Creates

Page 38: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

38 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

javax.jms.Queue senderQueue = session.createQueue(“sQueue”);

javax.jms.MessageProducer sender = session.createProducer(senderQueue);

Sender.send (msg,javax.jms.DeliveryMode.PERSISTENT,javax.jms.Message.DEFAULT_PRIORITY,MESSAGE_LIFESPAN)

….

Sender.close();

Creating a Producer

session

Queue

MessageProducer

createQueue( String queueName )

createProducer( Queue queue ) createProducer( Topic topic )

TopiccreateTopic( String topicName )

Page 39: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

39 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Creating a Consumer

session

Queue

MessageConsumer

createQueue( String queueName )

createConsumer( Queue queue )

createConsumer ( Topic topic )

javax.jms.Queue receiveQueue = session.createQueue(“rQueue”);

javax.jms.MessageConsumer receiver = session.createConsumer(receiveQueue);

Receiver.setMessageListener (listener);

Connect.start();

….

receiver.close();

TopiccreateTopic( String topicName )

Page 40: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

40 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Message Types

Message type Message body

TextMessage A Java String

ObjectMessage A serializable Java object

MapMessage Name/value pairs, where names are Java strings and values are java primitive types

StreamMessage A sequential stream of primitives

BytesMessage An uninterrupted stream of bytes

XMLMessage A Java String formatted as a tagged XML document

MultipartMessage Zero or more parts; each part can be a JMS message or arbitrary data

Page 41: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

41 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Select a Message Type

Major factors– Company message format requirements– Message volume and size– Proportion of keys to data– Consumer’s need

Suggestions– XML for inter-application communications– Text for simple test with no interpretation– Map for random access to data via keys– Stream for sequential access to data– Object for producer and consumer have access to the

same java class representing message– Byte for binary format message contents

Page 42: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

42 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Working on Messages

Producing messages– javax.jms.Session.create[message type]()– javax.jms.MessageProducer.send()

Consuming messages– Javax.jms.MessageListener.onMessage()– Javax.jms.MessageConsumer.receive()

javax.jms.MapMessage mmsg = session.createMapMessage();Progress.message.jclient.XMLMessage xmsg = ((progress.message.jclient.Session) session).createXMLMessage();

public void onMessage( javax.jms.Message aMessage){…javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;String string = textMessage.getText(); }…}

Page 43: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

43 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Use Case #1 - Producer

JDBC App

JMS adapter

(java sp)

ODBC App

Receiving App

Receiving App

SonicMQBroker

JMS adapter

Page 44: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

44 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – JMS producer adapter

public class JMSProducerAdapter

{

private javax.jms.Connection connect = null;

private javax.jms.Session session = null;

javax.jms.Queue queue = null;

javax.jms.Topic topic = null;

javax.jms.MessageProducer producer = null;

public JMSProducerAdapter(String broker, String username, String password){…}

public void createPTPProducer(String queueName) {…}

public void createPSProducer(String topicName) {…}

public void sendMapMsg (Integer iid, String iname,String iprice) {..}

public void sendXMLMsg ( String xmlString ) {…}

public void close () {…}

}

javax.jms.MapMessage msg=session.createMapMessage();

msg.setInt( "ID", iid.intValue());

msg.setString( "INAME", iname);

msg.setString( "IPRICE", iprice);

producer.send( msg,javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY,1800000);

progress.message.jclient.XMLMessage msg =

((progress.message.jclient.Session)session).createXMLMessage();

msg.setText(xmlString);

producer.send( msg,javax.jms.DeliveryMode.PERSISTENT,

javax.jms.Message.DEFAULT_PRIORITY,1800000);

if ( producer != null )

producer.close();

if ( session != null )

session.close();

if ( connect != null )

connect.close();

Page 45: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

45 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – JDBC Producer application

public class jdbctest_producer {

private static Connection connection=null;

private static Statement stmt=null;

private static CallableStatement callStmt=null;

private static JMSProducerAdapter jmsProducer=null;

public jdbctest_producer(String dbconnectstring,String username,String password){…}

private void connect(String dbconnectstring,String username,String password){…}

public void closeConnection(){…}

public ResultSet retrieveData(String query) throws Exception{…}

public void send_message (ResultSet rs) throws Exception{…}

public void generateXMLText (int iid, String iname, java.math.BigDecimal iprice){…}

public static void main(String [] args){…}

}

jmsProducer = new JMSProducerAdapter(DEFAULT_BROKER_NAME,DEFAULT_USERNAME,DEFAULT_PASSWORD);

jmsProducer.createPTPProducer(DEFAULT_QUEUE);

while (rs.next()){

id = rs.getInt(1);

generateXMLText(id, iname, iprice);

jmsProducer.sendXMLMsg ( xmlmsg.toString() );

}

rs.close();

StringBuffer xmlmsg = new StringBuffer(); xmlmsg.append ("<?xml version=\"1.0\"?>\n");

xmlmsg.append ("<message>\n");

xmlmsg.append (" <ItemID>" + iid + "</ItemID>\n");

xmlmsg.append (" <ItemName>" + iname + "</ItemName>\n");

xmlmsg.append (" <ItemPrice>" + iprice + "</ItemPrice>\n");

xmlmsg.append ("</message>\n");

Page 46: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

46 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example–ODBC Producer application

SQLRETURN ODBC_Class::SelectRecords(SQLCHAR * SQLStmt,char *Tname)

{

st = SQLExecDirect (StmtHandle, SQLStmt, SQL_NTS);

st = SQLBindCol (StmtHandle, 1, SQL_C_LONG, (SQLPOINTER) &ID, sizeof(long) , &cbID);

st = SQLBindCol (StmtHandle, 2, SQL_C_CHAR, (SQLPOINTER) Name, sizeof(Name), NULL);

st = SQLBindCol (StmtHandle, 3, SQL_C_CHAR, (SQLPOINTER) Price, sizeof(Price), &cbID);

while (st != SQL_NO_DATA)

{

st = SQLFetch(StmtHandle);

if (st != SQL_NO_DATA) SendMessage(ID,Name,Price,Tname);

}

}

SQLRETURN ODBC_Class::SendMessage(long iid, SQLCHAR* iname, SQLCHAR* iprice,char *Tname)

{

st=SQLBindParameter (CallStmtHandle, 1, SQL_PARAM_INPUT,SQL_C_LONG, SQL_INTEGER,0, 0, &iid, 4, &cbID);

st=SQLBindParameter (CallStmtHandle, 2, SQL_PARAM_INPUT,SQL_C_CHAR, SQL_CHAR,30, 0, iname, 30, NULL);

st=SQLBindParameter (CallStmtHandle, 3, SQL_PARAM_INPUT,SQL_C_CHAR, SQL_CHAR,10, 0, iprice, 10, NULL);

st=SQLExecDirect(CallStmtHandle, (SQLCHAR*)"{ call JMSProducerAdapter(?,?,?) } ", SQL_NTS);

}

st=SQLExecDirect(CallStmtHandle, (SQLCHAR*)"{ call JMSProducerAdapter(?,?,?) } ",

SQL_NTS);

Page 47: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

47 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – Java Stored Procedure JMS producer adapterCREATE PROCEDURE JMSProducerAdapter( IN id INTEGER, IN iname VARCHAR(30),IN iprice VARCHAR(10) )

IMPORT

import java.sql.* ;

BEGIN

JMSProducerAdapter jmsProducer=null;

String DEFAULT_BROKER_NAME = "localhost:2506";

String DEFAULT_USERNAME = "wang";

String DEFAULT_PASSWORD = "password";

String DEFAULT_QUEUE = "SampleQ1";

// Invoking the JMS adapter Java object

jmsProducer = new JMSProducerAdapter (DEFAULT_BROKER_NAME, DEFAULT_USERNAME,DEFAULT_PASSWORD);

jmsProducer.createPTPProducer(DEFAULT_QUEUE);

jmsProducer.sendMapMsg (id, iname, iprice);

jmsProducer.close();

END

jmsProducer = new JMSProducerAdapter (DEFAULT_BROKER_NAME, DEFAULT_USERNAME,

DEFAULT_PASSWORD);

jmsProducer.createPTPProducer(DEFAULT_QUEUE);

jmsProducer.sendMapMsg (id, iname, iprice);

jmsProducer.close();

Page 48: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

48 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Use Case #2 - Consumer

JMS Adapter

(java sp)

SonicMQBroker

Sending App

Sending App

JDBC App ODBC App

JMS Adapter

Page 49: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

49 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – JMS consumer adapter public class JMSConsumerAdapter implements javax.jms.MessageListener

{

private javax.jms.Connection connect = null;

private javax.jms.Session session = null;

private javax.jms.Queue queue = null;

private javax.jms.Topic topic = null;

private javax.jms.MessageConsumer consumer = null;

jdbctest_consumer jdbcobj = null; // The JDBC application object

public Integer[] ids = new Integer[20];

public String[] names = new String[20];

public String[] prices = new String[20];

public int msgCnt = 0;

public JMSConsumerAdapter(String broker, String username, String password){…}

public void createPTPConsumer(String queueName){…}

public void createPSConsumer(String topicName){…}

private void printDocNodes( org.w3c.dom.Node node, int indentSpaces ){…}

public void onMessage( javax.jms.Message aMessage) {…}

public void close () {…}

public static void main(String [] args){…}

}

if (aMessage instanceof javax.jms.MapMessage)

{

javax.jms.MapMessage mapMessage =

(javax.jms.MapMessage) aMessage;

int id = mapMessage.getInt("ID");

String name = mapMessage.getString("INAME");

String price = (String)mapMessage.getObject("IPRICE");

jdbcobj.newItem(id,name,price);

}

if (aMessage instanceof progress.message.jclient.XMLMessage) {

progress.message.jclient.XMLMessage xmlMessage = (progress.message.jclient.XMLMessage) aMessage;

org.w3c.dom.Document doc = xmlMessage.getDocument();

org.w3c.dom.NodeList nodes = null;

nodes = doc.getElementsByTagName("ItemID");

String id = (nodes.getLength() > 0) ? nodes.item(0).getFirstChild().getNodeValue() : "unknown";

}

queue = session.createQueue (queueName);

consumer = session.createConsumer(queue);

consumer.setMessageListener(this);

connect.start();

Page 50: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

50 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – JDBC consumer application

public class Jdbctest_Consumer implements javax.jms.MessageListener {

public void onMessage( javax.jms.Message aMessage)

{

// Cast the message as a text message.

javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;

// Passing the message

receive_message = textMessage.getText();

insertRecord(receive_message);

updateRecord(receive_message);

} public void insertRecord(String msgText){…}

Public void updateRecord(String msgText){…}

}

Page 51: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

51 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – Java Stored Procedure JMS consumer adapterCREATE PROCEDURE JMSConsumerAdapter(IN sleeptime Integer)

RESULT ( id INTEGER, name VARCHAR(30), price VARCHAR(10))

IMPORT

import java.sql.* ;

BEGIN

// Create the JMS adapter java object

JMSConsumerAdapter jmsConsumer = new

JMSConsumerAdapter(DEFAULT_BROKER_NAME,DEFAULT_USERNAME,DEFAULT_PASSWORD,true);

// PTP model with queue

jmsConsumer.createPTPConsumer(DEFAULT_QUEUE);

// Sleep to get more messages

java.lang.Thread.sleep(sleeptime.longValue());

// Translate the JMS message into the result set

for (int i=0; i< jmsConsumer.msgCnt; i++) {

SQLResultSet.set(1, jmsConsumer.ids[i]);

SQLResultSet.set(2, jmsConsumer.names[i]);

SQLResultSet.set(3, jmsConsumer.prices[i]);

SQLResultSet.insert();

}

// Close

jmsConsumer.close();

END

jmsConsumer = new JMSConsumerAdapter ( DEFAULT_BROKER_NAME, DEFAULT_USERNAME, DEFAULT_PASSWORD,true);

jmsConsumer.createPTPConsumer(DEFAULT_QUEUE);

Page 52: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

52 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – ODBC ConsumerSQLRETURN ODBC_Class::ProcessMessage()

{

SQLRETURN st;

SQLINTEGER cbID = 0;

long sleeptime = 600;

long ID = 0;

SQLCHAR Name [30];

SQLCHAR Price[10];

st=SQLBindParameter (CallStmtHandle,1,SQL_PARAM_INPUT,SQL_C_LONG,SQL_INTEGER,0,0,&sleeptime,4,&cbID);

st=SQLExecDirect(CallStmtHandle, (SQLCHAR*)"{ call JMSConsumerAdapter(?) } ", SQL_NTS);

if (st == SQL_SUCCESS) {

st = SQLBindCol (CallStmtHandle, 1, SQL_C_LONG, (SQLPOINTER) &ID, sizeof(long) , &cbID);

st = SQLBindCol (CallStmtHandle, 2, SQL_C_CHAR, (SQLPOINTER) Name, sizeof(Name), NULL);

st = SQLBindCol (CallStmtHandle, 3, SQL_C_CHAR, (SQLPOINTER) Price, sizeof(Price), &cbID);

while (st != SQL_NO_DATA){

st = SQLFetch(CallStmtHandle);

if (st != SQL_NO_DATA){…}}

}

return PASS;

}

st=SQLBindParameter (CallStmtHandle, 1, SQL_PARAM_INPUT,SQL_C_LONG, SQL_INTEGER,0, 0, &sleeptime, 4, &cbID);

st=SQLExecDirect(CallStmtHandle, (SQLCHAR*)"{ call JMSConsumerAdapter(?) } ", SQL_NTS);st = SQLBindCol (CallStmtHandle, 1, SQL_C_LONG,

(SQLPOINTER) &ID, sizeof(long) , &cbID);

st = SQLFetch(CallStmtHandle);

Page 53: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

53 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Use Case #3 – Database Trigger

JMS adapter

(java sp)

Java trigger

SonicMQBroker

Receiving App

Receiving App

JMS

adapter

Page 54: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

54 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Example – Insert Triggercreate trigger tb1_insert_trig1

after insert on tb1

REFERENCING NEWROW

for each row

IMPORT

import java.sql.* ;

BEGIN

// Get the new record from the NEWROW object

Integer id = (Integer)NEWROW.getValue (1,INTEGER);

String iname = (String)NEWROW.getValue (2,VARCHAR);

java.math.BigDecimal iprice = (java.math.BigDecimal)NEWROW.getValue (3,NUMERIC);

// Create the JMS adapter java object

JMSProducerAdapter jmsProducer = new JMSProducerAdapter(DEFAULT_BROKER_NAME,DEFAULT_USERNAME,DEFAULT_PASSWORD);

// PTP model with queue

jmsProducer.createPTPProducer(DEFAULT_QUEUE);

// Send the data

jmsProducer.sendMapMsg (id, iname, iprice.toString());

// Close

jmsProducer.close();

END

JMSProducerAdapter jmsProducer = new JMSProducerAdapter ( DEFAULT_BROKER_NAME, DEFAULT_USERNAME,

DEFAULT_PASSWORD);

jmsProducer.createPTPProducer(DEFAULT_QUEUE);

jmsProducer.sendMapMsg (id, iname, iprice.toString());

jmsProducer.close();

Page 55: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

55 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL and SonicMQ

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions

Page 56: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

56 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Demo – Supplier and Retailer

SonicMQBroker

Retailer Java App

Retailer Java AppOE SQL DB

Supplier Java App

(sports equipment vendor)

Java trigger

JDBC driver

JMS

Adding New product

Changing product’s price

Browsing orders

JMS

Placing orders

Show new product

Show price changes

JMS

JMS

Page 57: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

57 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Demo – Supplier and Retailer

Supplier database update for– Product’s price changes

– New arrival products

– Receiving orders from Retailer Supplier database’s Java trigger

– Fired up and calling the JMS Adapter to send the updated information

Retailer’s application– Receiving Supplier’s products updates

– Sending orders to Supplier

Page 58: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

58 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

OpenEdge SQL and SonicMQ

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions

Page 59: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

59 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

In Summary – You can do it now !

SQL programmers are able to use JMS/SonicMQ to communicate their JDBC or ODBC applications

Java stored procedures are a great OpenEdge SQL feature to take advantage of JMS

It is easy to develop

J2EE

ODBC Any

Any

.NET

JDBC

SonicMQBroker

OpenEdge

SQL DB

OpenEdge

SQL DB

Page 60: OpenEdge® SQL & SonicMQ®: Using JMS with SQL Applications Pat Bonser.

60 OpenEdge SQL and SonicMQ© 2005 Progress Software Corporation

Questions?

JMS and SonicMQ OpenEdge SQL Integration Demo Summary and Questions


Recommended