Solved

How to put a binary File in Websphere MQ

Posted on 2008-10-07
3
3,017 Views
Last Modified: 2013-12-11
Hi,

I am new to MQ. I am using the attached program to put a Text message in the Websphere MQ in C#. Now I need to put a binary file to the Remote Queue. How can I do that? Any code sample available?

Regards,

using System;

using IBM.WMQ;

 

public class MQSample1

{

    private String qManager = "QMQB01"; //define name of queue

    //manager to connect to.

    private MQQueueManager qMgr;  //define a queue manager object

 

    static void Main(string[] args)

    {

        new MQSample1();

    }

    public MQSample1()

    {

        try

        {

            //Create a connection to the queue manager

            qMgr = new MQQueueManager(qManager);

 

            //Set up the options on the queue we wish to open...

            //Note.All WebSphere MQ Options are prefixed with MQC

            int openOptions =  MQC.MQOO_OUTPUT;

            //MQC.MQOO_INPUT_AS_Q_DEF |

            //Now specify the queue that we wish to open,

            //and the open options...

            MQQueue system_default_local_queue = qMgr.AccessQueue("Q.EZL01.SEP.CMCC.001.S1", openOptions);

           

            //Define a simple WebSphere MQ message,and write some text in UTF format..

            MQMessage hello_world = new MQMessage();

            hello_world.WriteUTF("Hello World!");

 

            //specify the message options...

            MQPutMessageOptions pmo = new MQPutMessageOptions(); //accept the defaults,

 

            //same as MQPMO_DEFAULT

            //put the message on the queue

            system_default_local_queue.Put(hello_world, pmo);

 

            //Close the queue...

            system_default_local_queue.Close();

            //Disconnect from the queue manager

            qMgr.Disconnect();

        }

        //If an error has occurred in the above,try to identify what went wrong

 

        //Was it a WebSphere MQ error?

        catch (MQException ex)

        {

            Console.WriteLine("A WebSphere MQ error occurred :Completion code " +

            ex.CompletionCode + "Reason code " + ex.ReasonCode);

        }

        //Was it a System error?

        catch (System.Exception ex)

        {

            Console.WriteLine("A System error occurred:" + ex);

        }

    }

}//end of sample

Open in new window

0
Comment
Question by:kakali
  • 2
3 Comments
 

Author Comment

by:kakali
Comment Utility
Is there any expert to help me in this problem please.............
0
 
LVL 5

Accepted Solution

by:
lgacs earned 250 total points
Comment Utility
1) Use
   hello_world.write( byte[] );
instead of
    hello_world.WriteUTF("Hello World!");

2) Set the FORMAT field in MQMD to 'MQC.MQFMT_NONE' (8 spaces).
   hello_world.format = MQC.MQFMT_NONE;
0
 

Author Comment

by:kakali
Comment Utility
Many thanks. Yes I can now upload the binary file. But I need to set some property which is not the MQ Default property. I have some code example where the JMS is used to set these properties but I need to set these property as well. How can I set those property ?

MQQueueConnectionFactory factory = new MQQueueConnectionFactory();
factory.setTransportType(1);
factory.setHostName("172.30.28.61");
factory.setPort(1414);
factory.setChannel("SYSTEM.DEF.SVRCONN");
factory.setCCSID(437);
factory.setQueueManager("QMQB01");
qConn = factory.createQueueConnection("qbuser", "password");
qSession = qConn.createQueueSession(false, 1);
MQQueue q = new MQQueue("Q.EZL01.SEP.CMCC.001.02");
sender = qSession.createSender(q);
BytesMessage msg = qSession.createBytesMessage();
msg.setStringProperty("FILENAME", filename);
msg.setStringProperty("BLOB_ID", blobID);
msg.writeBytes(binMessage);
sender.send(msg);
sender.close();
qSession.close();
qConn.close();
As in the above code I also have to set those two property "FILENAME" & "BLOBID". How can I set those property using MQMessage in C#.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now