ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexGeneral IBM MQ SupportMQ message is not downloading sometime

Post new topicReply to topic
MQ message is not downloading sometime View previous topic :: View next topic
Author Message
sahasudipta
PostPosted: Wed Feb 20, 2019 3:29 am Post subject: MQ message is not downloading sometime Reply with quote

Newbie

Joined: 05 Jul 2018
Posts: 9

Hello ,

I wrote code to connect remote mq and download the message but sometime some message is missing . I'm posting my code . Can anyone tell me what is the error in this code

Code:

using System;
using IBM.WMQ;
using System.Diagnostics;
using System.IO;
using System.Xml;
using System.Linq;
using System.Xml.Linq;
using System.Configuration;
using System.Timers;

namespace MQ_listner
{
    internal class MQReader
    {
        private static MQQueueManager queueManager;
        private static MQMessage queueMessage;
        private static MQGetMessageOptions queueGetMessageOptions;
        private static MQQueue queue;
        static string strReturn = "";
        static string message = "";
        static string mqexception = "";
        static string connerror = "";
        static string QueueName;
        static string QueueManagerName;
        static string ChannelInfo;
        static string channelName;
        static string PortNumber;
        static string transportType;
        static string connectionName;
        static bool running;
        static bool conresult;
        static string checkconnexp;
        static bool connerrorflag;
        static bool checkconnresult;


        public MQReader()
        {
        }


        public static bool connectMQ()
        {
            bool flag;
            QueueManagerName = ConfigurationManager.AppSettings["QueueManager"];
            QueueName = ConfigurationManager.AppSettings["Queuename"];
            ChannelInfo = ConfigurationManager.AppSettings["ChannelInformation"];
            PortNumber = ConfigurationManager.AppSettings["Port"];
            char[] separator = { '/' };
            string[] ChannelParams;
            ChannelParams = ChannelInfo.Split(separator);
            channelName = ConfigurationManager.AppSettings["Channel"];
            transportType = ConfigurationManager.AppSettings["TransportType"];
            connectionName = ConfigurationManager.AppSettings["ConnectionName"];

            try
            {
                queueManager = new MQQueueManager(QueueManagerName,
                       channelName, connectionName);
                queue = queueManager.AccessQueue(QueueName,
           MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
                connerror = "Connected Successfully";
                flag = true;
            }
            catch (MQException connectionexp)
            {
                connerror = "Exception: " + connectionexp.Message;
                logFile(connerror);
                flag = false;
            }

            return flag;
        }

        private static void logFile(string errormsg)
        {
            string path = ConfigurationManager.AppSettings["logFilePath"];
            string fileName = path + "MQLog" + DateTime.Now.Date.ToString("yyyyMMdd") + ".txt";
            System.IO.File.AppendAllText(fileName, errormsg + Environment.NewLine);

        }

        public static void getMessage()
        {
            conresult = connectMQ();
            running = true;


            while (running)
            {
                if (conresult == true)
                {
                    try
                    {
                        queueMessage = new MQMessage();
                        queueMessage.Format = MQC.MQFMT_STRING;
                        queueGetMessageOptions = new MQGetMessageOptions();
                        queueGetMessageOptions.Options |= MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING;
                        queueGetMessageOptions.WaitInterval = 60000;
                        queue.Get(queueMessage, queueGetMessageOptions);
                        message = queueMessage.ReadString(queueMessage.MessageLength);
                       
                       
                    }
                    catch (MQException exp)
                    {
                        mqexception = exp.Message;
                        message = "Exception: " + mqexception;
                    }

                    if (message != "Exception: " + mqexception)
                    {
                        string path = ConfigurationManager.AppSettings["xmlFilePath"];
                        string fileName = path + "MQMessage" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";
                        System.IO.File.WriteAllText(fileName, message);
         
                    }
                    else   
                    {

                        logFile(message);
                        queueManager.Close();
                        queueManager.Disconnect();
                        conresult = false;
                    }

                }

                if (conresult == false)
                {
                   
                    conresult = connectMQ();
                   

                }

            }

        }

        public void InitializeConnections()
        {
            getMessage();
        }

       

        public void StopIt()
        {
            queueManager.Disconnect();
            running = false;
        }
    }
}


Please help
Back to top
View user's profile Send private message
exerk
PostPosted: Wed Feb 20, 2019 3:43 am Post subject: Reply with quote

Jedi Council

Joined: 02 Nov 2006
Posts: 5993

Please define what you mean by "...sometime some message is missing..."? Are you getting MQRC 2033 when the wait state has elapsed?
_________________
It's puzzling, I don't think I've ever seen anything quite like this before...and it's hard to soar like an eagle when you're surrounded by turkeys.

Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Feb 20, 2019 4:59 am Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 25488
Location: Ohio, USA

exerk wrote:
Please define what you mean by "...sometime some message is missing..."? Are you getting MQRC 2033 when the wait state has elapsed?




Or at least tell us what's captured in the logs.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Wed Feb 20, 2019 3:56 pm Post subject: Re: MQ message is not downloading sometime Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3107
Location: London, ON Canada

I'll be polite and only say 'Yuk' to that code.

First off, C# is an object oriented language so you should learn how to use try, catch & finally.

sahasudipta wrote:
Code:
if (message != "Exception: " + mqexception)

What is that? That is not how you do string comparison and why isn't that code (of conditional "if") in the try{} section?

sahasudipta wrote:
Code:
string fileName = path + "MQMessage" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".xml";

Hummm. You didn't lose your messages, you threw them away. What happens if you get 2 or more messages during the same millisecond?

From the docs for WriteAllText:

Quote:
Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.


So, that means when you get 2 or more messages during the same millisecond the next one overwrites the previous one.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
sahasudipta2014
PostPosted: Fri Feb 22, 2019 1:26 am Post subject: Reply with quote

Newbie

Joined: 14 Feb 2019
Posts: 2

hello @Roger thank you for reply . I really appreciate it . It will improve my coding .Can you tell me any solution for this ? Is there any tool to monitor MQ activity like when message is put into MQ , when message downloaded .
Back to top
View user's profile Send private message
sahasudipta2014
PostPosted: Fri Feb 22, 2019 4:23 am Post subject: Reply with quote

Newbie

Joined: 14 Feb 2019
Posts: 2

hello exerk ,

can you suggest any way or any tool which will trace/log when message is send into remote mq .
Back to top
View user's profile Send private message
mvic
PostPosted: Fri Feb 22, 2019 10:44 am Post subject: Reply with quote

Jedi

Joined: 09 Mar 2004
Posts: 2076

sahasudipta2014 wrote:
can you suggest any way or any tool which will trace/log when message is send into remote mq .

Just type mq trace or mq activity trace into Google.
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Fri Feb 22, 2019 2:01 pm Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3107
Location: London, ON Canada

sahasudipta2014 wrote:
Can you tell me any solution for this ?

Sure. Here are 2 ideas:

(1) Do not overwrite but append the new data to the file or

(2) Create a method to check if the file already exists, if it does, add a counter to the file name and check again until the file is not found then use that file name.

Also, why don't you put a message counter in your program and output when it is done. Hence, you should have the same number of output files as what the message counter states.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexGeneral IBM MQ SupportMQ message is not downloading sometime
Jump to:



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.