+

Search Tips | Advanced Search

Controlling message context information

When we use the MQPUT or MQPUT1 call to put a message on a queue, we can specify that the queue manager is to add some default context information to the message descriptor. Applications that have the appropriate level of authority can add extra context information. We can use the options field in the MQPMO structure to control context information.

Message context information allows the application that retrieves the message to find out about the originator of the message. All context information is stored in the context fields of the message descriptor. The type of information falls into identity, origin, and user context information.

To control context information, use the Options field in the MQPMO structure.

If we do not specify any options for context information, the queue manager overwrites context information that might already be in the message descriptor with the identity and context information that it has generated for your message. This is the same as specifying the MQPMO_DEFAULT_CONTEXT option. You might want this default context information when you create a new message (for example, when processing user input from an inquiry screen).

If you want no context information associated with your message, use the MQPMO_NO_CONTEXT option. When putting a message with no context, any authority checks made by IBM MQ are made using a blank user ID. A blank user ID cannot be assigned explicit authority to IBM MQ resources but is treated as a member of the special group 'nobody'. For more details on the special group nobody, see Installable services interface reference information.

We can do context setting using MQOPEN followed by MQPUT using the MQOO_ option and MQPMO_ option indicated in the following sections. We can also do context setting using just an MQPUT1, in which case you just need to select the MQPMO_ option indicated in the sections below.

The following sections of this topic explain the use of identity context, user context, and all context.


Passing identity context

In general, programs should pass identity context information from message to message around an application until the data reaches its final destination.

Programs should change the origin context information each time that they change the data. However, applications that want to change or set any context information must have the appropriate level of authority. The queue manager checks this authority when the applications open the queues; they must have authority to use the appropriate context options for the MQOPEN call.

If our application gets a message, processes the data from the message, then puts the changed data into another message (possibly for processing by another application), the application must pass the identity context information from the original message to the new message. We can allow the queue manager to create the origin context information.

To save the context information from the original message, use the MQOO_SAVE_ALL_CONTEXT option when you open the queue for getting the message. This is in addition to any other options we use with the MQOPEN call. Note, however, that we cannot save context information if we only browse the message.

When you create the second message:


Passing user context

We cannot choose to pass only user context. To pass user context when putting a message, specify MQPMO_PASS_ALL_CONTEXT. Any properties in the user context are passed in the same way as the origin context.

When an MQPUT or MQPUT1 takes place and the context is being passed, all properties in the user context are passed from the retrieved message to the put message. Any user context properties that the putting application has altered are put with their original values. Any user context properties that the putting application has deleted are restored in the put message. Any user context properties that the putting application has added to the message are retained.


Passing all context

If our application gets a message, and puts the message data (unchanged) into another message, the application must pass all (identity, origin, and user) context information from the original message to the new message. An example of an application that might do this is a message mover, which moves messages from one queue to another.

Follow the same procedure as for passing identity context, except that we use the MQOPEN option MQOO_PASS_ALL_CONTEXT and the put-message option MQPMO_PASS_ALL_CONTEXT.


Set identity context

If you want to set the identity context information for a message:

Note: When you set some (but not all) of the identity context fields using the MQOO_SET_IDENTITY_CONTEXT and MQPMO_SET_IDENTITY_CONTEXT options, it is important to realize that the queue manager does not set any of the other fields.

In order to modify any of the message context options, you must have the appropriate authorizations to issue the call. For example, in order to use MQOO_SET_IDENTITY_CONTEXT or MQPMO_SET_IDENTITY_CONTEXT, you must have +setid permission.


Set user context

To set a property in the user context, set the Context field of the message property descriptor (MQPD) to MQPD_USER_CONTEXT when you make the MQSETMP call.

You do not need any special authority to set a property in the user context. User context has no MQOO_SET_* or MQPMO_SET_* context options.


Set all context

If you want to set both the identity and the origin context information for a message:
  1. Open the queue using the MQOO_SET_ALL_CONTEXT option.
  2. Put the message on the queue, specifying the MQPMO_SET_ALL_CONTEXT option. In the message descriptor, specify whatever identity and origin context information you require.
Appropriate authority is needed for each type of context setting.