Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to put a binary File in Websphere MQ

Posted on 2008-10-07
3
3,107 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
ID: 22666422
Is there any expert to help me in this problem please.............
0
 
LVL 5

Accepted Solution

by:
lgacs earned 250 total points
ID: 22667655
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
ID: 22675569
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let’s list some of the technologies that enable smooth teleworking. 
All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

856 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