DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • Top Six React Development Tools
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables

Trending

  • Top Six React Development Tools
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables
  1. DZone
  2. Coding
  3. Languages
  4. The Splendid State of Python and WebSphere MQ Programming

The Splendid State of Python and WebSphere MQ Programming

Dariusz Suchojad user avatar by
Dariusz Suchojad
·
Sep. 14, 13 · Interview
Like (1)
Save
Tweet
Share
7.31K Views

Join the DZone community and get the full member experience.

Join For Free

Intro

This post summarizes the options programmers have when it comes to WebSphere MQ programming with Python.

WebSphere MQ is a tool for everyone, and no matter what your background is, C, C++, Java, COBOL, Visual Basic or anything, you will find something interesting in Python too.

If you've never heard of WebSphere MQ before, I'll explain it, risking a slight oversimplification.  In queueing, WebSphere AMQP is to AMQP what Oracle DB is to PostgreSQL in RDBMS land.

The Actors

There are three libraries and projects Python programmers can pick from, and they're all open source.  All of them let you connect and exchange messages with any MQ application, regardless of what language or languages it's written in.

  • PyMQI
  • Spring Python
  • Zato

Each of them builds on the previous one to provide more useful features with less manual coding.

PyMQI

PyMQI is the lowest level library that provides direct access to all the primitives that are usually associated with MQ programming in other languages: queues, topics, queue managers, subscriptions, PCF commands and anything else that is needed for manipulating MQ objects directly.

PyMQI is the tool to use for quick one-off jobs, particularly if you're already familiar with MQI, which is a C API that WebSphere MQ provides. PyMQI mostly provides an object-oriented Python layer on top of MQI.

If you're an admin, and you need something convenient to build a useful tool very quickly, Python and PyMQI are the tools to use.

Here's some sample code to put a message in a queue:

import pymqi
 
queue_manager = 'QM01'
channel = 'SVRCONN.1'
host = '192.168.1.135'
port = '1434'
queue_name = 'TEST.1'
message = 'Hello from Python!'
conn_info = '{}({})'.format(host, port)
 
qmgr = pymqi.connect(queue_manager, channel, conn_info)
 
queue = pymqi.Queue(qmgr, queue_name)
queue.put(message)
queue.close()
 
qmgr.disconnect()

PyMQI usage examples.


Spring Python

Spring Python takes the good parts of Spring for Java and implements them in a Pythonic way. Among other things, one can find the support for JMS WebSphere MQ programming in Python.  In other words, completely seamless means to exchange messages with Java apps from Python ones.

For those who are curious, this is achieved by manually constructing and parsing all the MQRFH2 headers required behind the scenes.

On top of that, it has connection factories, background listeners and a JMS Template, which is a higher-level object with which to manipulate MQ messages.

Use Spring Python if:

  • You need a higher level API.
  • You're okay with manual coding.
  • You've already used Spring for Java elsewhere.

Note that Spring Python now requires the use of JMS, but this is something that will soon change and this post will be updated to reflect it.

Here's the sample code to put a message in a queue:

from springpython.jms.core import JmsTemplate
from springpython.jms.factory import WebSphereMQConnectionFactory
 
qm = 'QM.1'
channel = 'SVRCONN1.1'
host = '192.168.1.121'
port = '1434'
queue1 = 'TEST.1'
 
factory = WebSphereMQConnectionFactory(qm, channel, host, port)
 
jms_template = JmsTemplate(factory)
jms_template.send('Hello world', queue1)
 
factory.destroy()

Spring Python usage examples

Zato

[Full disclosure: I am the creator of Zato]

Zato is a full-fledged ESB and backend application server written in Python which supports MQ and a lot of other technologies and protocols and data formats.

Its abstractions are on the highest level, and it requires very little coding. In fact, there's no MQ-specific programming needed at all. One can simply focus on receiving requests (which requires zero coding) and producing the messages to send while Zato establishes connections, reconnects when necessary, adds headers and anything else that should be done.  You just create a message and the rest is handled automatically.

Here's the sample code to put a message in a queue:

from zato.server.service import Service
 
class MyService(Service):
  def handle(self):
    self.outgoing.jms_wmq.send('msg', 'connection-name', 'Q.1')

More Zato MQ usage examples.

One can forget about the particularities of WebSphere MQ because such details are configured using the GUI (as below), API, CLI or en masse in JSON.

Form for creating an MQ connection definitionForm for creating an MQ connection itself

Summary

  • Use PyMQI for quick tasks or low-level functionality.
  • Use Spring Python for a higher level API or if you're familiar with Java.
  • Use Zato if you want a full-fledged ESB and application server with load-balancing, hot-deployment and other features.
Python (language)

Published at DZone with permission of Dariusz Suchojad. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Top Six React Development Tools
  • Decoding eBPF Observability: How eBPF Transforms Observability as We Know It
  • Building the World's Most Resilient To-Do List Application With Node.js, K8s, and Distributed SQL
  • The Role of AI and Programming in the Gaming Industry: A Look Beyond the Tables

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: