280 likes | 497 Views
EAS306 Building a Chat Server with EAServer and PowerBuilder. Dean Jones [TeamSybase] CEO of PowerObjects dean@powerobjects.com (612) 339-3355. Who We Are…. PowerObjects Multi-Million dollar consulting company Sybase Consulting Partner Value Added reseller Premier consulting partner
E N D
EAS306 Building a Chat Server with EAServer and PowerBuilder Dean Jones [TeamSybase]CEO of PowerObjects dean@powerobjects.com(612) 339-3355
Who We Are… • PowerObjects • Multi-Million dollar consulting company • Sybase Consulting Partner • Value Added reseller • Premier consulting partner • Custom Solution Provider • Specialize in EAServer and Web Development • Offer Web application hosting • Certified Developers staff • PowerBuilder, Java and Microsoft Certifies • Member of Team Sybase
Overview • Building a Chat server using PowerBuilder and EAServer • Using Java Message Service • Publishing Messages • Subscribing to Messages • PowerBuilder Components • Pushed messages onMessage Event • Taking it one step further
Message Service • EAServer’s message service provides a powerful means by which to leverage multiple threads in your distributed applications
Message Service • The message service provides queues for message consumers • Allows message producers to send messages to specified queues (point-to-point messaging) • Publish messages with specified topics that may be of interest to registered consumers (publish/subscribe messaging) • There are two parts to the message service • A Publisher • A Consumer
Message Producer EAServer Client or Component MessageService Proxy Message Consumer MessageServer Publish MessageTopic MessageQueue MessageQueue Client or Component onMessage Notify MessageQueue Message Service
Publishing Messages • To publish a message, there are three steps: • Create a proxy for message service • Populate the message • Publish
PowerBuilder Proxy • Before you can send a message to the queue you must generate MessageService Proxy • NOTE: The objects created will have an issue with wchar • To fix you must edit the source and replace wchar data type with String data type
Populate the Message • A message is a structure of information to send to the server
Publish • Publish a message with the specified message topic. • A copy of this message will be sent to the queues for all consumers who have registered a message selector that returns TRUE when applied to this message void publish ( in string topic, in CtsComponents::Message msg, in long options );
Chat Application • You type a message into a single line edit and send when the user clicks Send.
ctscomponents_message msg ctscomponents_property prop ctscomponents_propertyvalue val val = create ctscomponents_propertyvalue val.stringValue( sle_message.text ) prop.value = val msg.text = sle_name.text + ": "+ sle_message.text msg.props[1] = prop msg.key = ims.getMessageKey() msg.replyTo = "" ims.publish( "chat", msg, 0 ) sle_message.text = "" sle_message.SetFocus() Chat Application
Consuming Messages • To retrieve messages, there are two options: • First is to pull messages from a given queue • Second option is to let the message service push messages • EAServer cannot push messages to a PowerBuilder client application, it can only push messages to PowerBuilder component • EAServer can push messages to a Java client
Consuming Messages • Consumers of messages can either pull messages or have them pushed. There are three steps to pulling messages: • Connect to the Message Service • Specify a Queue and a Topic • Receive messages • To be a consumer of pushed messages, three steps must be taken: • Implement Message Listener • Code the onMessage event • Register the receiving component using code or message service manager
Connect to Message Service ctsComponents_MessageService cms ctscomponents_messageseq cseq ctscomponents_messagequeue cmsg ctscomponents_message cm ctscomponents_messagekey after string sz_queue int i connection c c = CREATE connection c.application = "" c.location = "iiop://jones-dean:9000" c.userid = "jagadmin" c.password = "sarah" c.driver = "jaguar" c.ConnectToServer() c.CreateInstance(cms, "CtsComponents/MessageService")
Receive Messages sz_queue = cms.getUniqueName(1) cmsg = cms.getMessageQueue(sz_queue,"",0) cms.addselector(sz_queue, "topic='chat'" ) do while 1 < 2 //CtsComponents_Messageseq seq cseq = cmsg.receive( 0, 30 ) For i = 1 to UpperBound(cseq.item) cm = cseq.item[i] arg_notify.post of_notify( cm.Text ) after = cm.key Next loop return 1
Pushed Messages • Receiving messages that are pushed from the message service’s receive() method is straightforward. • Code a component with an onmessage() method with the following signature: Return [none] onmessage( ctscomponents_message msg )
Pushed Messages • You can create a new component and add the onmessage() method or you can create a component that implements an existing interface • In this example, we’ll add logic to the onmessage() method that writes to the log and indicates when the component is called
Pushed Messages • It’s important to note that if you code a custom component that does not implement CstComponent/MessageListener, you must add this interface to your component using Jaguar Manager (Figure 12). The custom interface has the component’s actual IDL; you must add the MessageListener IDL
Pushed Messages • After creating and deploying the component, you must go into Jaguar Manager and configure the message queue to listen for messages. Under Message Service you can configure a new queue. Do this by right clicking on Configured Queues and selecting New.
Message flow n_messagelistener Push Messages MessageService EAServer Client Side Chat Client I Chat Client II Publish Message Pull Messages
Taking it one Step Further • Keeping track of who’s connected • Sending messages to selected users • Receiving messages from selected users
New Getting more Help • Mentoring • New PowerBuilder 9 Book • Internet and Distributed Application Development • EAServer API Interface • EAServer on-line help • Forums
New Getting more Help • Sybase Tools Seminar April 2004 • Minneapolis, MN • Over 150 Attendees • Six Sessions • Panel Discussion with all experts and Sybase product managers • http://www.powerobjects.com/seminar
Contact PowerObjects • Send E-mail and Questions: • dean@powerobjects.com • Visit our Web-site: • www.powerobjects.com • Call Us: • Office (612) 339-3355
Grab one of my business card Dean JonesChief Executive Officerwww.powerobjects.com 401 2nd Ave. S. Suite 843Minneapolis, MN 55401Office 612.339.3355cell 612.701.4017fax 612.339.4433 dean@powerobjects.com