private void Purge()
        {
            var properties = new Hashtable
            {
                { MQC.HOST_NAME_PROPERTY, Settings.Hostname },
                { MQC.PORT_PROPERTY, Settings.Port },
                { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT },
                { MQC.CHANNEL_PROPERTY, Settings.Channel }
            };

            using (var queueManager = new MQQueueManager(Settings.QueueManager, properties))
            {
                var agent   = new PCFMessageAgent(queueManager);
                var request = new PCFMessage(CMQCFC.MQCMD_CLEAR_Q);
                request.AddParameter(MQC.MQCA_Q_NAME, endpointAddress.QueueName);

                try
                {
                    agent.Send(request);
                }
                catch (PCFException ex)
                {
                    Logger.Warn(string.Format("Could not purge queue ({0}) at startup", endpointAddress.QueueName), ex);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Display list of queue names and queue depth for each queue
        /// </summary>
        public static void InquireQueue()
        {
            PCFMessageAgent messageAgent = null;

            try
            {
                // Create bindings connection to queue manager
                messageAgent = new PCFMessageAgent("DEMOQMGR");
                // Build Inquire command to query queue name
                PCFMessage reqeuestMessage = new PCFMessage(MQC.MQCMD_INQUIRE_Q);
                reqeuestMessage.AddParameter(MQC.MQCA_Q_NAME, "*");
                // Send request and receive response
                PCFMessage[] pcfResponse = messageAgent.Send(reqeuestMessage);
                // Process and print response.
                int pcfResponseLen = pcfResponse.Length;
                for (int pcfResponseIdx = 0; pcfResponseIdx < pcfResponseLen; pcfResponseIdx++)
                {
                    try
                    {
                        String qName  = pcfResponse[pcfResponseIdx].GetStringParameterValue(MQC.MQCA_Q_NAME);
                        int    qDepth = pcfResponse[pcfResponseIdx].GetIntParameterValue(MQC.MQIA_CURRENT_Q_DEPTH);
                        Console.WriteLine("QName: " + qName + "  Depth: " + qDepth);
                    }
                    catch (PCFException pcfex)
                    {
                        //Ignore exception and get the next response
                    }
                }
            }
            catch (PCFException pcfEx)
            {
                Console.Write(pcfEx);
            }
            catch (MQException ex)
            {
                Console.Write(ex);
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            finally
            {
                if (messageAgent != null)
                {
                    messageAgent.Disconnect();
                }
            }
        }
Пример #3
0
        public void CreateQueueIfNecessary(Address address, string account)
        {
            var queueName = WebSphereMqAddress.GetQueueName(address);

            var properties = new Hashtable
            {
                { MQC.HOST_NAME_PROPERTY, Settings.Hostname },
                { MQC.PORT_PROPERTY, Settings.Port },
                { MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES },
                { MQC.CHANNEL_PROPERTY, Settings.Channel },
                { MQC.SSL_CIPHER_SPEC_PROPERTY, Settings.SslCipherSpec },
                { MQC.SSL_CERT_STORE_PROPERTY, Settings.SslKeyRepository },
                { MQC.SSL_PEER_NAME_PROPERTY, Settings.SslPeerName }
            };

            using (var queueManager = new MQQueueManager(Settings.QueueManager, properties))
            {
                var agent   = new PCFMessageAgent(queueManager);
                var request = new PCFMessage(CMQCFC.MQCMD_CREATE_Q);
                request.AddParameter(MQC.MQCA_Q_NAME, queueName);
                request.AddParameter(MQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL);
                request.AddParameter(MQC.MQIA_MAX_Q_DEPTH, Settings.MaxQueueDepth);

                try
                {
                    agent.Send(request);
                }
                catch (PCFException ex)
                {
                    if (ex.ReasonCode == PCFException.MQRCCF_CFST_STRING_LENGTH_ERR)
                    {
                        throw new ArgumentException(String.Format("Queue name too long:{0}", queueName));
                    }

                    if (ex.ReasonCode != PCFException.MQRCCF_OBJECT_ALREADY_EXISTS)
                    {
                        throw;
                    }
                }
            }
        }
Пример #4
0
 public MqPcfManager(string connection, string queueManager, string channel, int port)
 {
     _agent = MqHelper.CreatePcfAgent(connection, queueManager, channel, port);
 }