示例#1
0
        public static string TestConnection(MqConnectionSettings mqConnectionSettings)
        {
            var queueManager = MqManagerFactory.Create(mqConnectionSettings);
            var response     = queueManager.IsConnected
                ? "Connected Successfully"
                : "Problem accesing WebSphere MQ";

            queueManager.Disconnect();
            return(response);
        }
示例#2
0
        public static string GetMessage(MqConnectionSettings mqConnectionSettings, string queueName, bool browse, bool firstMessage = true)
        {
            var queueManager   = MqManagerFactory.Create(mqConnectionSettings);
            var mqQueue        = GetMqQueue(queueName, browse, queueManager);
            var messageContent = string.Empty;

            try
            {
                var mqMsg = MqUploader.CreateNewMqMessage();
                messageContent = mqQueue.GetMessageContent(mqMsg, browse, firstMessage);
                mqMsg.ClearMessage();
                queueManager.Commit();
            }
            catch (Exception)
            {
                queueManager.Disconnect();
                mqQueue?.Close();
            }
            return(messageContent);
        }
示例#3
0
        private const int MqEncoding = MQC.CODESET_819; // "iso-8859-1"

        public static string SendMessage(MqConnectionSettings mqConnectionSettings, string queueName, string message)
        {
            var queueManager = MqManagerFactory.Create(mqConnectionSettings);

            var queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);


            var queueMessage           = CreateNewMqMessage();
            var queuePutMessageOptions = new MQPutMessageOptions();

            AddMessageContent(message, queueMessage);

            queue.Put(queueMessage, queuePutMessageOptions);
            queue.Close();
            queueManager.Commit();
            queueManager.Disconnect();

            var msgId = Convert.ToBase64String(queueMessage.MessageId ?? new byte[0]);

            return(msgId);
        }