public List <MqSubscription> Inquire(string name) { var collection = new List <MqSubscription>(); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_INQUIRE_SUBSCRIPTION); pcfCmd.addParameter(com.ibm.mq.constants.CMQCFC.MQCACF_SUB_NAME, $"{name}*"); PCFMessage[] pcfResponse = _agent.send(pcfCmd); for (int i = 0; i < pcfResponse.Length; i++) { //https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q088050_.htm string subName = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQCFC.MQCACF_SUB_NAME); string topicString = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_TOPIC_STRING); string topic = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_TOPIC_NAME); string selector = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQCFC.MQCACF_SUB_SELECTOR); string dest = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQCFC.MQCACF_DESTINATION); collection.Add(new MqSubscription { Name = subName, TopicName = topic, TopicString = topicString, Selector = selector, Destination = dest }); } } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } return(collection); }
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); } } }
/// <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(); } } }
public void Delete(string name) { Trace.WriteLine($"Deleting subscription {name} ..."); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_DELETE_SUBSCRIPTION); pcfCmd.addParameter(com.ibm.mq.constants.CMQCFC.MQCACF_SUB_NAME, name); _agent.send(pcfCmd); } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } }
public void Create(string name, string topicString, string destination) { Trace.WriteLine($"Creating subscription {name} for topicString {topicString} and destination {destination} ..."); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_CREATE_SUBSCRIPTION); pcfCmd.addParameter(com.ibm.mq.constants.CMQCFC.MQCACF_SUB_NAME, name); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_TOPIC_STRING, topicString); pcfCmd.addParameter(com.ibm.mq.constants.CMQCFC.MQCACF_DESTINATION, destination); _agent.send(pcfCmd); } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } }
public List <MqQueue> Inquire(string name) { var collection = new List <MqQueue>(); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_INQUIRE_Q); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_Q_NAME, $"{name}*"); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL); PCFMessage[] pcfResponse = _agent.send(pcfCmd); var names = new List <string>(); for (int i = 0; i < pcfResponse.Length; i++) { //https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_7.5.0/com.ibm.mq.ref.adm.doc/q087800_.htm string qName = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_Q_NAME); int depth = (int)pcfResponse[i].getIntParameterValue(com.ibm.mq.constants.CMQC.MQIA_CURRENT_Q_DEPTH); int maxDepth = (int)pcfResponse[i].getIntParameterValue(com.ibm.mq.constants.CMQC.MQIA_MAX_Q_DEPTH); int type = (int)pcfResponse[i].getIntParameterValue(com.ibm.mq.constants.CMQC.MQIA_Q_TYPE); string baseObject = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_BASE_OBJECT_NAME); string description = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_Q_DESC); string clusterName = (string)pcfResponse[i].getParameterValue(com.ibm.mq.constants.CMQC.MQCA_CLUSTER_NAME); collection.Add(new MqQueue { Name = qName, Depth = depth, MaxDepth = maxDepth, BaseObject = baseObject, Type = type, ClusterName = clusterName, Description = description }); } return(collection); } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } return(collection); }
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; } } } }
/// <summary> /// Creates an alias queue /// </summary> /// <param name="name">The name of the alias queue</param> /// <param name="baseObject">The name of the local queue to use as the baseObject</param> /// <param name="clusterName">The name of the cluster this alias queue will be visible in</param> /// <param name="description">Option description of the queue</param> public void Create(string name, string baseObject, string clusterName, string description = "") { Trace.WriteLine($"Creating alias queue {name} for base object {baseObject} in cluster {clusterName} ..."); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_CREATE_Q); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_Q_NAME, name); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQIA_Q_TYPE, MQC.MQQT_ALIAS); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_BASE_OBJECT_NAME, baseObject); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_CLUSTER_NAME, clusterName); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_Q_DESC, description); _agent.send(pcfCmd); } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } }
/// <summary> /// Creates a local queue /// </summary> /// <param name="name">The name of the local queue</param> /// <param name="description">Option description of the queue</param> public void Create(string name, string description = "") { Trace.WriteLine($"Creating local queue {name} ..."); try { PCFMessage pcfCmd = new PCFMessage(com.ibm.mq.constants.CMQCFC.MQCMD_CREATE_Q); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_Q_NAME, name); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQIA_Q_TYPE, MQC.MQQT_LOCAL); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQCA_Q_DESC, description); pcfCmd.addParameter(com.ibm.mq.constants.CMQC.MQIA_MAX_Q_DEPTH, 100000); _agent.send(pcfCmd); } catch (MQException e) { Trace.WriteLine($"MQException::ReasonCode: {e.reasonCode} | {e.getMessage()}"); } }