Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to put a binary File in Websphere MQ

Posted on 2008-10-07
3
Medium Priority
?
3,278 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
[X]
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
  • 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 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Invest in your employees with these five simple steps to improve employee engagement and retention.
Have you ever run into that annoying problem where the computer won't boot?  Wouldn't it be great if you had a tool that would make that disk boot again?  I have found one tool that works more often than not ...
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seveā€¦

610 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