Pages

03/08/2015

[Spotfire] Send JMS message to EMS with IronPython script

Want to take your Spotfire analysis to the next level? What about adding an extra level of interactivity to it?

Maybe you also have a BusinessWorks or BusinessEvents engine somewhere feeding data to it, and you spot something that requires your intervention, or maybe you want to replay a flow for some reason. Sound like you need to have Spotfire communicate with those engines.

HTTP? Sure it works. What if you prefer JMS instead because you also have your own EMS server?

Here is a sample script that sends an XML payload to a queue on your EMS server using the EMS APIs:

 import clr  
 import sys  
   
 sys.path.append(r"C:\ems\ems\8.2\bin") # path of EMS dll  
 clr.AddReference ("TIBCO.EMS.dll") # the EMS dll  
 import TIBCO.EMS # import namespace from EMS dll  
   
 qcf = TIBCO.EMS.QueueConnectionFactory("tcp://localhost:7222") # EMS URL, even fault tolerant  
 qconn = qcf.CreateQueueConnection("admin", "") # EMS user and password  
 q = TIBCO.EMS.Queue("sample") # EMS queue  
   
 #False, capital F, means “no transaction”, if True, you need to do a Commit() after sending the message(s)  
 qs = qconn.CreateQueueSession(False, TIBCO.EMS.SessionMode.ExplicitClientAcknowledge) # or others under TIBCO.EMS.SessionMode at https://docs.tibco.com/pub/ems/8.2.1/doc/html/TIB_ems_api_reference/api/dotnetdoc/html/namespace_t_i_b_c_o_1_1_e_m_s.html#a9544ca6fbdea89581893e64e907cf953  
   
 sender = qs.CreateSender(q)  
   
 body = "<NODE>VALUE</NODE>" # either XML or simple text  
   
 message = qs.CreateTextMessage(body)  
 sender.Send(message) # or add more parameters: delivery mode, priority, TTL  
   
 #qs.Commit() # commit only if session is transacted  
   
 # close connection  
 qs.Close()  
 qconn.Close()  

No comments:

Post a Comment

With great power comes great responsibility