Solved

How to put a binary File in Websphere MQ

Posted on 2008-10-07
3
3,086 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DataBasix Technologies Lead Commander download 2 26
Map software access 4 30
Advice for Customer Feedback and Retention system required for car dealer 3 90
C# Gridview 1 29
A list of useful business intelligence software.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
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.

776 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