+

Search Tips | Advanced Search

Sample applications for .NET

To run your own .NET applications, use the instructions for the verification programs, substituting the application name in place of the sample applications.

The following sample applications are supplied:

  • A put message application
  • A get message application
  • A 'hello world' application
  • A publish/subscribe application
  • An application using message properties

All these sample applications are supplied in the C# language, and some are also supplied in C++ and Visual Basic. We can write applications in any language supported by .NET.

    "Put message" program SPUT (nmqsput.cs, mmqsput.cpp, vmqsput.vb)
    This program shows how to put a message to a named queue. The program has three parameters:

    • The name of a queue (required), for example, SYSTEM.DEFAULT.LOCAL.QUEUE
    • The name of a queue manager (optional)
    • The definition of a channel (optional), for example, SYSTEM.DEF.SVRCONN/TCP/hostname(1414)

    If no queue manager name is given, the queue manager defaults to the default local queue manager. If a channel is defined, it has the same format as the MQSERVER environment variable.

    "Get message" program SGET (nmqsget.cs, mmqsget.cpp, vmqsget.vb)
    This program shows how to get a message from a named queue. The program has three parameters:

    • The name of a queue (required), for example, SYSTEM.DEFAULT.LOCAL.QUEUE
    • The name of a queue manager (optional)
    • The definition of a channel (optional), for example, SYSTEM.DEF.SVRCONN/TCP/hostname(1414)

    If no queue manager name is given, the queue manager defaults to the default local queue manager. If a channel is defined, it has the same format as the MQSERVER environment variable.

    "Hello World" program (nmqwrld.cs, mmqwrld.cpp, vmqwrld.vb)
    This program shows how to put and get a message. The program has three parameters:

    • The name of a queue (optional), for example, SYSTEM.DEFAULT.LOCAL.QUEUE or SYSTEM.DEFAULT.MODEL.QUEUE
    • The name of a queue manager (optional)
    • A channel definition (optional), for example, SYSTEM.DEF.SVRCONN/TCP/hostname(1414)

    If no queue name is given, the name defaults to SYSTEM.DEFAULT.LOCAL.QUEUE. If no queue manager name is given, the queue manager defaults to the default local queue manager.

    "Publish/subscribe" program (MQPubSubSample.cs)
    This program shows how to use IBM MQ publish/subscribe. It is supplied in C# only. The program has two parameters:

    "Message properties" program (MQMessagePropertiesSample.cs)
    This program shows how to use message properties. It is supplied in C# only. The program has two parameters:

We can verify your installation by compiling and running these applications.


Installation locations

The sample applications are installed to the following locations, according to the language in which they are written. MQ_INSTALLATION_PATH represents the high-level directory in which IBM MQ is installed.

    C#

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\nmqswrld.cs

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\nmqsput.cs

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\nmqsget.cs

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\MQPubSubSample.cs

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\MQMessagePropertiesSample.cs

    Managed C++

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\mcp\mmqswrld.cpp

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\mcp\mmqsput.cpp

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\mcp\mmqsget.cpp

    Visual Basic

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\vmqswrld.vb

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\vmqsput.vb

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\vmqsget.vb

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\xmqswrld.vb

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\xmqsput.vb

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\xmqsget.vb


Building the sample applications

To build the sample applications, a batch file is supplied for each language.

    C#

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\cs\bldcssamp.bat

    The bldcssamp.bat file contains a line for each sample, which is all that is necessary to build this sample program:
    csc /t:exe /r:System.dll /r:amqmdnet.dll /lib: MQ_INSTALLATION_PATH\bin
    /out:nmqwrld.exe nmqwrld.cs
    

    Managed C++

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\mcp\bldmcpsamp.bat

    The bldmcpsamp.bat file contains a line for each sample, which is all that is necessary to build this sample program:
    cl /clr:oldsyntax MQ_INSTALLATION_PATH\bin mmqwrld.cpp
    
    To compile these applications on Microsoft Visual Studio 2003/.NET SDKv1.1, replace the compile command:
    cl /clr:oldsyntax MQ_INSTALLATION_PATH\bin mmqwrld.cpp
    
    with
    cl /clr MQ_INSTALLATION_PATH\bin mmqwrld.cpp
    

    Visual Basic

    MQ_INSTALLATION_PATH\Tools\dotnet\samples\vb\bldvbsamp.bat

    The bldvbsamp.bat file contains a line for each sample, which is all that is necessary to build this sample program:
    vbc /r:System.dll /r: MQ_INSTALLATION_PATH\bin\amqmdnet.dll /out:vmqwrld.exe vmqwrld.vb
    


Samples for using IBM MQ with Microsoft .NET Core

From Version 9.2.0, IBM MQ supports .NET Core for IBM MQ .NET applications in Windows environments. IBM MQ classes for .NET Standard, including samples, are installed by default as part of the standard IBM MQ installation.

The sample applications for IBM MQ .NET are installed in &MQINSTALL_PATH&/samp/dotnet/samples/cs/core/base. A script is also provided, which can be used to compile the samples.

We can build the samples by using the supplied build.bat files. There is one build.bat for each sample in the following location on Windows:

  • MQ\tools\dotnet\samples\cs\core\base\SimpleGet
  • MQ\tools\dotnet\samples\cs\core\base\SimplePut

From Version 9.2.0, IBM MQ also supports Core for applications in Linux environments.

For more infromation about using IBM MQ with Microsoft .NET Core, see Installing IBM MQ classes for .NET Standard.

Parent topic: Getting started with IBM MQ classes for .NET

Last updated: 2020-10-04