Skip to content

Commit 7e8e28b

Browse files
committed
Add JWT sample
1 parent 1827acc commit 7e8e28b

File tree

7 files changed

+374
-129
lines changed

7 files changed

+374
-129
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
## xxx xx 2023 - v5.5.x
5+
- ibmmq - Add simple tracing for MQI calls (MQIGO_TRACE env var)
6+
- samples - Add sample obtaining and using a JWT token
7+
48
## Nov 13 2023 - v5.5.3
59
- mqmetric - MQ 9.3 permits resource subscriptions for queues with '/' in name
610

README.md

Lines changed: 74 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,84 +2,82 @@
22

33
This repository demonstrates how you can call IBM MQ from applications written in the Go language.
44

5-
The repository originally also contained programs that exported MQ statistics to
6-
monitoring systems. These programs have been moved to a GitHub repository called [mq-metric-samples](https://github.com/ibm-messaging/mq-metric-samples).
5+
The repository originally also contained programs that exported MQ statistics to monitoring systems. These programs have
6+
been moved to a GitHub repository called [mq-metric-samples](https://github.com/ibm-messaging/mq-metric-samples).
77

88
A minimum level of MQ V8 is required to build these packages, although it should be possible to connect as a client to even older versions of queue manager.
99

1010
## Health Warning
1111

12-
This package is provided as-is with no guarantees of support or updates. You cannot use
13-
IBM formal support channels (Cases/PMRs) for assistance with material in this repository.
12+
This package is provided as-is with no guarantees of support or updates. You cannot use IBM formal support channels
13+
(Cases/PMRs) for assistance with material in this repository.
1414

15-
There are also no guarantees of compatibility with any future versions of the package; the API
16-
is subject to change based on any feedback. Versioned releases are made in this repository
17-
to assist with using stable APIs. Future versions will follow semver guidance so that breaking changes
18-
will only be done with a new major version number on the module.
15+
There are also no guarantees of compatibility with any future versions of the package; the API is subject to change
16+
based on any feedback. Versioned releases are made in this repository to assist with using stable APIs. Future versions
17+
will follow semver guidance so that breaking changes will only be done with a new major version number on the module.
1918

2019
See the [DEPRECATIONS](DEPRECATIONS.md) file for any planned changes to the API.
2120

2221
## MQI Description
2322

24-
The `ibmmq` directory contains a Go package, exposing an MQI-like interface.
23+
The `ibmmq` directory contains a Go package, exposing an MQI-like interface. With a few tiny exceptions noted below, the
24+
package implements the full-function MQI. Any application you might have written using the C or COBOL MQI ought to be
25+
easily convertible to the Go equivalent.
2526

26-
The intention is to give an API that is more natural for Go programmers than the
27-
common procedural MQI. For example, fixed length string arrays from the C API such
28-
as MQCHAR48 are represented by the native Go string type. Conversion between these
29-
types is handled within the `ibmmq` package itself, removing the need for Go programmers
30-
to know about it.
27+
The intention is to give an API that is more natural for Go programmers than the common procedural MQI. For example,
28+
fixed length string arrays from the C API such as MQCHAR48 are represented by the native Go string type. Conversion
29+
between these types is handled within the `ibmmq` package itself, removing the need for Go programmers to know about it.
3130

32-
Sample programs are provided to demonstrate various features of using the MQI. See the
33-
README in the `samples` directory for more information about those programs. Detailed information about the MQI and application design can be found in the MQ product
34-
documentation. Although that doesn't mention Go as a language, the principles for all
35-
applications apply.
31+
Sample programs are provided to demonstrate various features of using the MQI. See the [README](samples/README.md) in
32+
the `samples` directory for more information about those programs. Detailed information about the MQI and application
33+
design can be found in the MQ product documentation. Although that doesn't mention Go as a language, the principles for
34+
all applications apply.
3635

37-
The `mqmetric` directory contains functions to help monitoring programs access MQ status and statistics. This package is not needed for general application programs.
36+
A limited trace capability is available so you can see the MQI verbs being executed. To use this, either set the
37+
`MQIGO_TRACE` environment variable to any non-empty value or call the `ibmmq.SetTrace(true)` function.
38+
39+
The `mqmetric` directory contains functions to help monitoring programs access MQ status and statistics. This package is
40+
not needed for general application programs.
3841

3942
## Using the package
4043

41-
To use code in this repository, you will need to be able to build Go applications, and
42-
have a copy of MQ installed to build against. It uses `cgo` to access the MQI C
43-
structures and definitions. It assumes that MQ has been installed in the default
44-
location (on a Linux platform this would be `/opt/mqm`) but this can be changed
45-
with environment variables if necessary.
44+
To use code in this repository, you will need to be able to build Go applications. You must also have a copy of MQ
45+
installed to build against. The package uses `cgo` to access the MQI C structures and definitions. It assumes that MQ has been
46+
installed in the default location (on a Linux platform this would be `/opt/mqm`) but this can be changed with
47+
environment variables if necessary.
4648

47-
Windows compatibility is also included. Current versions of the Go compiler
48-
permit standard Windows paths (eg including spaces) so the CGO directives
49-
can point at the normal MQ install path.
49+
Windows compatibility is also included. Current versions of the Go compiler permit standard Windows paths (eg including
50+
spaces) so the CGO directives can point at the normal MQ install path.
5051

5152
## Getting started
5253

53-
If you are unfamiliar with Go, the following steps can help create a working environment
54-
with source code in a suitable tree. Initial setup tends to be platform-specific,
55-
but subsequent steps are independent of the platform.
54+
If you are unfamiliar with Go, the following steps can help create a working environment with source code in a suitable
55+
tree. Initial setup tends to be platform-specific, but subsequent steps are independent of the platform.
5656

5757
### MQ Client SDK
58-
The MQ Client SDK for C programs is required in order to compile and run Go programs. You may have this from an MQ Client installation image (eg rpm, dep for Linux; msi for
59-
Windows).
58+
The MQ Client SDK for C programs is required in order to compile and run Go programs. You may have this from an MQ
59+
Client installation image (eg rpm, dep for Linux; msi for Windows).
6060

61-
For Linux x64 and Windows systems, you may also choose to use the
62-
MQ Redistributable Client package which is a simple zip/tar file that does not need
63-
any privileges to install:
61+
For Linux x64 and Windows systems, you may also choose to use the MQ Redistributable Client package which is a simple
62+
zip/tar file that does not need any privileges to install:
6463

6564
* Download [IBM MQ redistributable client](https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist)
6665
* Unpack archive to fixed directory. E.g. `c:\IBM-MQC-Redist-Win64` or `/opt/mqm`.
6766

6867
### Linux
6968

70-
* Install the Go runtime and compiler. On Linux, the packaging may vary but a typical
71-
directory for the code is `/usr/lib/golang`.
69+
* Install the Go runtime and compiler. On Linux, the packaging may vary but a typical directory for the code is
70+
`/usr/lib/golang`.
7271
* Create a working directory. For example, ```mkdir $HOME/gowork```
7372
* Install the git client and the gcc C compiler
7473

7574
### Windows
7675

7776
* Install the Go runtime and compiler. On Windows, the common directory is `c:\Go`
78-
* Ensure you have a gcc-based compiler. The variant that seems to be recommended for cgo is
79-
the [tdm-gcc-64](https://jmeubank.github.io/tdm-gcc/download/) 64-bit compiler suite.
80-
The default `gcc` compiler from Cygwin does not work because it tries to build a
81-
Cygwin-enabled executable but the MQ libraries do not work in that model;
82-
the `mingw` versions build Windows-native programs.
77+
* Ensure you have a gcc-based compiler. The variant that seems to be recommended for cgo is the
78+
[tdm-gcc-64](https://jmeubank.github.io/tdm-gcc/download/) 64-bit compiler suite. The default `gcc` compiler from
79+
Cygwin does not work because it tries to build a Cygwin-enabled executable but the MQ libraries do not work in that
80+
model; the `mingw` versions build Windows-native programs.
8381
* Create a working directory. For example, `mkdir c:\Gowork`
8482
* Set an environment variable for the compiler
8583
```
@@ -94,11 +92,10 @@ set CC=x86_64-w64-mingw32-gcc.exe
9492

9593
`git clone [email protected]:ibm-messaging/mq-golang.git src/github.com/ibm-messaging/mq-golang`
9694

97-
* If you have not installed MQ libraries into the default location, then set environment variables
98-
for the C compiler to recognise those directories. You may then get messages from the compiler
99-
saying that the default MQ directories cannot be found, but those warnings can be ignored.
100-
The exact values for these environment variables will vary by platform, but follow the
101-
corresponding CFLAGS/LDFLAGS values in `mqi.go`
95+
* If you have not installed MQ libraries into the default location, then set environment variables for the C compiler to
96+
recognise those directories. You may then get messages from the compiler saying that the default MQ directories cannot
97+
be found, but those warnings can be ignored. The exact values for these environment variables will vary by platform,
98+
but follow the corresponding CFLAGS/LDFLAGS values in `mqi.go`
10299

103100
For example, on Linux:
104101

@@ -122,27 +119,25 @@ Or on Windows:
122119
go build -o /tmp/mqitest mqitest/*.go
123120
```
124121

125-
At this point, you should have a compiled copy of the program in `/tmp`. See the
126-
`samples` directory for more sample programs.
122+
At this point, you should have a compiled copy of the program in `/tmp`. See the `samples` directory for more sample
123+
programs.
127124

128125

129126
## Building in a container
130-
The `buildSamples.sh` script in this directory can also be used to create a container which will
131-
install the MQ Client SDK, compile the samples and copy them to a local directory. If you use this approach, you do not need
132-
to install a local copy of the compiler and associated tools, though you will still need a copy of
133-
the MQ C client runtime libraries for wherever you execute the programs.
127+
The `buildSamples.sh` script in this directory can also be used to create a container which will install the MQ Client
128+
SDK, compile the samples and copy them to a local directory. If you use this approach, you do not need to install a
129+
local copy of the compiler and associated tools, though you will still need a copy of the MQ C client runtime libraries
130+
for wherever you execute the programs.
134131

135132
## Go Modules
136-
The packages in this repository are set up to be used as Go modules. See the `go.mod` file in
137-
the root of the repository.
133+
The packages in this repository are set up to be used as Go modules. See the `go.mod` file in the root of the
134+
repository.
138135

139-
Support for modules started to be introduced around Go 1.11 and has been firmed up in various
140-
modification level updates in each of the compiler levels since then. It is now recommended to
141-
use at least version 1.17 of the compiler.
136+
Support for modules started to be introduced around Go 1.11 and has been firmed up in various modification level updates
137+
in each of the compiler levels since then. It is now recommended to use at least version 1.17 of the compiler.
142138

143-
Use of modules means that packages do not need to be independently compiled or
144-
installed. Environment variables such as `GOROOT` and `GOPATH` that were previously required are
145-
now redundant in module mode.
139+
Use of modules means that packages do not need to be independently compiled or installed. Environment variables such as
140+
`GOROOT` and `GOPATH` that were previously required are now redundant in module mode.
146141

147142
To use the MQ module in your application, your `go.mod` file contains
148143

@@ -158,8 +153,8 @@ and your application code includes
158153
import ibmmq "github.com/ibm-messaging/mq-golang/v5/ibmmq"
159154
```
160155

161-
If you have not moved to using modules in your application, you should continue using the older levels
162-
of these packages. For example, you can continue to use `dep` with `Gopkg.toml` referring to
156+
If you have not moved to using modules in your application, you should continue using the older levels of these
157+
packages. For example, you can continue to use `dep` with `Gopkg.toml` referring to
163158

164159
```
165160
[[constraint]]
@@ -170,8 +165,8 @@ Those older versions are not maintained, so it is strongly recommended you do mo
170165

171166
## Related Projects
172167

173-
These GitHub-hosted projects are related to or derived from this one. This is not a complete list. Please
174-
let me know, via an issue, if you have another project that might be suitable for inclusion here.
168+
These GitHub-hosted projects are related to or derived from this one. This is not a complete list. Please let me know,
169+
via an issue, if you have another project that might be suitable for inclusion here.
175170

176171
| Repository | Description |
177172
|--------------------------------------|---------------|
@@ -185,14 +180,17 @@ let me know, via an issue, if you have another project that might be suitable fo
185180

186181
### Package 'ibmmq'
187182
* All regular MQI verbs are available through the `ibmmq` package.
188-
* The only unimplemented area of MQI function is the use of Distribution Lists: they were
189-
rarely used, and the Publish/Subscribe operations provide similar capability.
190-
* Go is not supported for writing MQ Exits, so structures and methods for those features
191-
are not included.
183+
* The only unimplemented area of MQI function is the use of Distribution Lists: they were rarely used, and the
184+
Publish/Subscribe operations provide similar capability.
185+
* Go is not supported for writing MQ Exits, so structures and methods for those features are not included.
192186

193187
### Package 'mqmetric'
194-
* The monitoring data published by the queue manager and exploited in the mqmetric package is not available before MQ V9. A limited set of metrics can be monitored for MQ V8 instances by setting the `ConnectionConfig.UsePublications` configuration option to `false`.
195-
* There is currently a queue manager limitation which does not permit resource publications to be made about queues whose name includes '/'. Attempting to monitor such a queue will result in a warning logged by the mqmetric package.
188+
* The monitoring data published by the queue manager and exploited in the mqmetric package is not available before MQ
189+
V9. A limited set of metrics can be monitored for MQ V8 instances by setting the `ConnectionConfig.UsePublications`
190+
configuration option to `false`.
191+
* There was a queue manager limitation which did not permit resource publications to be made about queues whose name
192+
includes '/'. This restriction was removed in MQ 9.3. Attempting to monitor such a queue on an older queue manager
193+
results in a warning logged by the mqmetric package.
196194

197195
## History
198196

@@ -203,13 +201,12 @@ See [CHANGELOG](CHANGELOG.md) in this directory.
203201
Feedback on the utility of this package, thoughts about whether it should be changed
204202
or extended are welcomed.
205203

206-
For feedback and issues relating specifically to this package, please use
207-
the [GitHub issue tracker](https://github.com/ibm-messaging/mq-golang/issues).
204+
For feedback and issues relating specifically to this package, please use the
205+
[GitHub issue tracker](https://github.com/ibm-messaging/mq-golang/issues).
208206

209-
Contributions to this package can be accepted under the terms of the Developer's Certificate
210-
of Origin, found in the [DCO file](DCO1.1.txt) of this repository. When
211-
submitting a pull request, you must include a statement stating you accept the terms
212-
in the DCO.
207+
Contributions to this package can be accepted under the terms of the Developer's Certificate of Origin, found in the
208+
[DCO file](DCO1.1.txt) of this repository. When submitting a pull request, you must include a statement stating you
209+
accept the terms in the DCO.
213210

214211

215212
## Copyright

0 commit comments

Comments
 (0)