MQSeries based file transfers using the pymqi module

Dariusz Suchojad dsuch at gefira.pl
Sun May 7 10:41:39 EDT 2006


Andrew Robert wrote:

 > Hi everyone,

Hello,

 > Has anyone developed a pymqi module based file transfer method for use
 > with WebSphere MQSeries v5.3?
 >
 > If so, would it be possible to point me towards examples of how this
 > was done?

I'm not sure I understand your question. Webshpere MQ expects your code
to give it a stream of bytes, there's nothing file-specific in using
base WMQ so it's your application's job to read a file, put its contents
onto the desired queue, and to get it off the queue some time later.

If the code below is not what you need then feel free to ask a more 
specific question :-)

import pymqi as mq

# Queue manager name
qm_name = "M01"

# Listener host and port
listener = "127.0.0.1(1414)"

# Channel to transfer data through
channel = "SYSTEM.DEF.SVRCONN"

# Input/output queue name
queue_name = "Q01"

# Make some data
file_name = "C:\\sample.txt"
sample_data = "Hello from PyMQI."
open(file_name,"w").write(sample_data)

# Connect to queue manager
qm = mq.QueueManager(None)
qm.connectTCPClient(qm_name, mq.cd(), channel, listener)

# Put a message onto the queue
queue = mq.Queue(qm, queue_name)
data = open(file_name).read()
queue.put(data)

# Close the queue, queue.put has implicitly opened the queue for output
# so we can't use the same pymqi.Queue object for getting the messages
# off the queue
queue.close()

# Now get the message, queue.get will implicitly open the queue for
# input
queue = mq.Queue(qm, queue_name)
msg = queue.get()
queue.close()

# Here's the message contents
print msg

-- 
Dariusz Suchojad



More information about the Python-list mailing list