Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ amqp-vertx/target/*
terraform.tfstate.*
terraform.tfstate

# Associated with the Python code
venv*
Python/tmp/

# Standard Eclipse control files
.project
.settings
.classpath


97 changes: 63 additions & 34 deletions Python/README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,91 @@
# IBM MQ Python samples
The python samples are based on https://dsuch.github.io/pymqi/
and have been tested with python 3.10.12,3.11.9 and 3.12.5
These samples use a Python library for the MQI to demonstrate basic messaging operations.

Python PyMQI library uses the IBM MQ C client libraries through the MQI interface.
The Python `ibmmq` library uses the IBM MQ C client libraries through the MQI interface.

The library needs to be compiled with a C compiler which you need to have installed in your development environment.
The Python library needs to be compiled with a C compiler which you need to have installed in your development
environment. For example, on MacOS we used `XCode`, on Windows the `Desktop development with C++` module inside Visual
Studio and on Ubuntu the `gcc` GNU Compiler Collection.

For example, on MacOS we used `XCode`, on Windows the `Desktop development with C++` module inside Visual Studio and on Ubuntu the `gcc` GNU Compiler Collection.
The samples use the same configuration file as other language samples in this repository.

Install/unzip IBM MQ client
## Client and SDK installation
### MacOS
Follow Step 1 from [this page](https://developer.ibm.com/tutorials/mq-macos-dev/) to install the SDK using brew. None of
the other steps on that page are required in order to run these Python samples.

## Mac
Alternatively you can download the IBM MQ MacOS toolkit from
[here](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/mactoolkit/)

[IBM MQ MacOS toolkit for developers download](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/mactoolkit/)
### Windows
The MQ Redistributable Client for Windows can be downloaded from
[here](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist/)

Add
`/opt/mqm/bin` and
`/opt/mqm/samp/bin`, to the PATH by editing `/etc/paths`
### Linux
The MQ Redistributed Client for Linux x64 can be downloaded from
[here](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist/)

execute the following command:
`export DYLD_LIBRARY_PATH=/opt/mqm/lib64`
For other platforms, you can use the regular MQ iamges to install, at minimum, the MQ Client and SDK components.

## IBM MQ Python package installation
You may like to work inside a Python virtual environment. If so, create and initialise that in the usual ways.
For example:

```
python -m venv my_venv
. my_venv/bin/activate
```

Then install the prerequsite package by running: `pip install ibmmq`.

## Windows
## Sample Configuration
All of the programs read a JSON-formatted configuration file. The name of the file can be given by setting the
`JSON_CONFIG` environment variable. If that is not set, the _env.json_ file from the parent directory is used. Edit the
configuration to match the configuration of the queue manager you are going to work with.

[Windows MQ redist client download](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist/)
## Running the programs
There are no parameters to any of the programs.

## Linux Ubuntu
You might need to run `setmqenv` to create environment variables pointing at your MQ installation libraries.

On MacOS, the `DYLD_LIBRARY_PATH` will usually need to be set to include the `/opt/mqm/lib64` directory:

`export DYLD_LIBRARY_PATH=/opt/mqm/lib64`

[Linux MQ redist client download](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist/)
If you are on Linux, you might need set the `LD_LIBRARY_PATH` to include the `/opt/mqm/lib64` directory:

For installation instructions please go to
#### [linux installation](../../mq-dev-patterns/installationDocs/linuxUbuntu-installationSteps.md)
`export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/mqm/lib64`

See [here](https://www.ibm.com/docs/en/ibm-mq/latest?topic=reference-setmqenv-set-mq-environment) for
more information about `setmqenv`.

## Run samples
On some systems, you might need to explicitly use the `python3` command instead of `python`.

To run the examples cd to the Python directory, and install the prerequsites by running :
### Put/Get
The `basicput` application places a short string message onto the queue.

`pip install pymqi`
`python ./basicput`

### Put / Get
`python basicput.py`
The `basicget` application reads all messages from the queue and displays the contents.

and
`python ./basicget`

`python basicget.py`
### Publish/Subscribe
Run these samples as a pair.

### Publish / Subscribe
`python basicpublish.py`
Start the `basicsubcribe` program in one window (or in the background) and immediately afterwards start the
`basicpublish` program in another window.

and
`python ./basicsubscribe`

`python basicsubscribe.py`
`python ./basicpublish`

### Request / Response
### Request/Response
Run these samples as a pair.

`python basicrequest.py`
Start the `basicresponse` program in one window (or in the background) and immediately afterwards start the
`basicrequest` program in another window.

and
`python ./basicresponse`

`python basicresponse.py`
`python ./basicrequest`
4 changes: 4 additions & 0 deletions Python/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# pylint: disable=invalid-name
# pylint doesn't like us being in a "Python" subdirectory, so disable that check

"""This file is deliberately left blank.
"""
Loading