MQ Light messaging from Microsoft®.NET™ (Part 2)

 View Only

MQ Light messaging from Microsoft®.NET™ (Part 2) 

Wed March 04, 2020 02:28 PM

MQ Light messaging from Microsoft®.NET™ (Part 2)


Matthew Whitehead
Published on 04/12/2017
 / Updated on 22/01/2018

 

Introduction

In the first article I showed how you can connect to queue managers from .NET applications using the Amqp.Net Lite library.

In this article we’ll look at how to control the client ID the application presents to the queue manager.

Setting a specific client ID

By default the Amqp.Net Lite client library generates a UID container ID to use in the AMQP open frame. MQ interprets the container ID as a client ID which can be used to identify and, if required, authorise specific applications to different MQ topics.

Here’s the output of runmqsc when viewing the AMQP channel status for a basic Amqp.Net Lite connection:

DIS CHSTATUS(*) CHLTYPE(AMQP) CLIENTID(*) ALL AMQ8417: Display Channel Status details. CHANNEL(MY.AMQP.CHANNEL) CHLTYPE(AMQP) CLIENTID(69854723-ca09-45b7-8162-cfce07c7b1b3) STATUS(RUNNING) CONNAME(0:0:0:0:0:0:0:1) AMQPKA(0) MCAUSER(MUSR_MQADMIN) CLNTUSER( ) MSGSNT(0) MSGRCVD(0) LSTMSGDA( ) LSTMSGTI( ) CHSTADA(2017-11-01) CHSTATI(15.11.10) PROTOCOL(AMQP)

You can see the CLIENTID field has the auto-generated value “69854723-ca09-45b7-8162-cfce07c7b1b3” from the library.

It would be useful to be able to set our own client ID so that we could identify individual applications more easily. In this post we’ll look at the changes we need to make to the code in part 1.

The code

In the original article we made a connection to the queue manager using the following Connection constructor:

public Connection(Address address, SaslProfile saslProfile, Open open, OnOpened onOpened)

We only provided the first 2 arguments and passed in null for the last two. To set our own container ID we must create an AMQP open frame ourselves and set the container ID to the one we want.

First create a new Open frame to pass to the Connection constructor:

Open openFrame = new Open();

Note: you will need to import the Amqp.Framing package by adding “using Amqp.Framing;” to the top of the file.

Now on the open frame specify the container ID you want to use:

openFrame.ContainerId = "amqpClient01";

Finally create a new connection passing in the open frame as the 3rd argument:

connection = new Connection(address, SaslProfile.Anonymous, openFrame, null);

Now with the same code from part 1 to create a Session and a ReceiverLink you can connect to the queue manager with your chosen client ID.

Checking the connection

Once you have connected to the queue manager you can use the same runmqsc commands we used before to check that the client ID has been set correctly:

DIS CHSTATUS(*) CHLTYPE(AMQP) CLIENTID(*) ALL AMQ8417: Display Channel Status details. CHANNEL(MY.AMQP.CHANNEL) CHLTYPE(AMQP) CLIENTID(amqpClient01) STATUS(RUNNING) CONNAME(0:0:0:0:0:0:0:1) AMQPKA(0) MCAUSER(MUSR_MQADMIN) CLNTUSER( ) MSGSNT(0) MSGRCVD(0) LSTMSGDA( ) LSTMSGTI( ) CHSTADA(2017-11-01) CHSTATI(15.11.10) PROTOCOL(AMQP)

and

DIS CONN(*) TYPE(CONN) WHERE (CLIENTID NE '') CLIENTID CONNAME AMQ8276: Display Connection details. CONN(A162F05925790601) EXTCONN(414D5143514D34202020202020202020) TYPE(CONN) CLIENTID(amqpClient01) CONNAME(0:0:0:0:0:0:0:1)

You can now more easily identify which connections you have coming into the queue manager and if you choose to adopt the client ID as the connection’s security context, authorise individual clients to specific MQ topics.

In the next post we will look at how multiple receivers can consume messages from a shared subscription.

 

Entry Details

Statistics
0 Favorited
3 Views
1 Files
0 Shares
3 Downloads
Attachment(s)
pdf file
MQ Light messaging from Microsoft®.NET™ (Part 2).pdf   118 KB   1 version
Uploaded - Wed March 04, 2020

Tags and Keywords

Related Entries and Links

No Related Resource entered.