Exemplo n.º 1
0
        /// <summary>
        ///   Create a WMQ connection factory and set relevant properties.
        /// </summary>
        /// <returns>A connection factory</returns>
        public static IConnectionFactory CreateConnectionFactory(XmsDestination destination)
        {
            // Create the connection factories factory
            XMSFactoryFactory factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

            // Use the connection factories factory to create a connection factory
            IConnectionFactory cf = factoryFactory.CreateConnectionFactory();

            // Set the properties
            cf.SetStringProperty(XMSC.WMQ_HOST_NAME, destination.HostName);
            cf.SetIntProperty(XMSC.WMQ_PORT, destination.Port);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, destination.Channel);
            cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
            // since null is not permited for queue manager, pass that as empty string
            // so that, while connecting to queue manager, it finds the default queue manager.
            cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, destination.Manager);

            //cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, Options.BrokerVersion.ValueAsNumber);

            // Integrator
            //if (Options.BrokerVersion.ValueAsNumber == XMSC.WMQ_BROKER_V2)
            //    cf.SetStringProperty(XMSC.WMQ_BROKER_PUBQ, Options.BrokerPublishQueue.Value);

            return (cf);
        }
Exemplo n.º 2
0
 public bool Equals(XmsDestination other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Queue, Queue) && Equals(other.HostName, HostName) && other.Port == Port &&
            Equals(other.Channel, Channel) && Equals(other.Manager, Manager);
 }
 private XmsPooledProducer PlainProducerFactory(Pool<XmsPooledProducer> pool, XmsDestination destination)
 {
     log.Info("Going to create new plain producer for destination {0}".FormatWith(destination));
     var producer = new XmsProducer(destination, transactional);
     var pooled = new XmsPooledProducer(pool, producer);
     return pooled;
 }
Exemplo n.º 4
0
 public XmsProducer(XmsDestination destination, bool transactional)
 {
     this.destination = destination;
     this.transactional = transactional;
     log.Debug("New physical producer created. About to connect.");
     Connect();
     log.Debug("New physical producer successfully connected.");
 }
 private Pool<XmsPooledProducer> PoolFactory(XmsDestination destination)
 {
     log.Info("Going to create new producer pool for destination {0}".FormatWith(destination));
     //TODO: make this configurable
     var store = new StackStore<XmsPooledProducer>(60.Seconds(), 30.Seconds());
     var pool = new Pool<XmsPooledProducer>(10, p => PlainProducerFactory(p, destination), store);
     return pool;
 }
        public IXmsProducer GetProducer(XmsDestination destination)
        {
            Pool<XmsPooledProducer> pool;
            if (!poolsByDestination.TryGetValue(destination, out pool))
            {
                lock (locker)
                {
                    pool = poolsByDestination.GetOrAdd(destination, PoolFactory);
                }
            }

            if (IsInTransaction && transactional)
            {
                log.Debug("Detected transaction scope on transactional provider. Using per scope producer.");

                // here we need to keep track of current instances within the current transaction scope
                // so we can return the same producers for given current thread, transaction and destination 
                var key = "{0}|{1}".FormatWith(Transaction.Current.TransactionInformation.LocalIdentifier, destination);

                if (!scopedProducers.ContainsKey(key))
                {
                    log.Debug("Detected that there is no pending scoped producer for {0}. Acquiring a new instance.".FormatWith(key));
                    var pooled = pool.Acquire();
                    var producer = (XmsProducer)pooled.Producer;

                    return scopedProducers.GetOrAdd(key, k => new XmsCommitPerScopeProducer(pooled, producer.Session,
                        () =>
                        {
                            log.Debug("Removing pending scoped producer for {0}.".FormatWith(key));
                            XmsCommitPerScopeProducer _;
                            scopedProducers.TryRemove(key, out _);
                        }));
                }
                log.Debug("Detected pending scoped producer for {0}. Reusing the existing instance.".FormatWith(key));
                return scopedProducers[key];
            }
            if (transactional)
            {
                var pooled = pool.Acquire();
                log.Debug("No transaction scope on transactional provider. Using per call producer.");
                var producer = (XmsProducer)pooled.Producer;
                return new XmsCommitPerCallProducer(pooled, producer.Session);
            }
            return pool.Acquire();
        }
        public IXmsConsumer GetConsumer(XmsDestination destination)
        {
            Pool<XmsPooledConsumer> pool;
            if (!poolsByDestination.TryGetValue(destination, out pool))
            {
                lock (locker)
                {
                    pool = poolsByDestination.GetOrAdd(destination, PoolFactory);
                }
            }
            var pooled = pool.Acquire();
            if (IsInTransaction)
            {
                log.Debug("Detected transaction scope. Wrapping the consumer in transacted consumer.");

                // not very nice, we need ot get the session somehow
                var producer = (XmsConsumer)pooled.Consumer;
                return new XmsTransactedConsumer(pooled, producer.Session);
            }
            return pooled;
        }
Exemplo n.º 8
0
        // TODO: test this
        public static void PopulateErrorQueueMessage(IBytesMessage toSend, IBM.XMS.IBytesMessage failed, XmsDestination xmsDestination)
        {
            var body = new byte[failed.BodyLength];
            if (body.Length > 0)
            {
                failed.ReadBytes(body, body.Length);
                toSend.WriteBytes(body);
            }
            toSend.JMSCorrelationID = failed.JMSCorrelationID;
            toSend.JMSDeliveryMode = failed.JMSDeliveryMode;
            toSend.CopyStringProperty(HEADER_RETURNADDRESS, failed);
            toSend.CopyStringProperty(HEADER_IDFORCORRELATION, failed);
            toSend.CopyStringProperty(HEADER_WINDOWSIDENTITYNAME, failed);
            toSend.CopyStringProperty(HEADER_MESSAGEINTENT, failed);

            var keys = failed.GetStringProperty(HEADER_NBSKEYS);
            var unwrapedKeys = UnwrapKeys(keys);
            foreach (var unwrapedKey in unwrapedKeys)
            {
                toSend.CopyStringProperty(unwrapedKey, failed);
            }

            toSend.CopyStringProperty(HEADER_NBSKEYS, failed);
            
            // error queue specific
            toSend.SetStringProperty(HEADER_FAILEDQUEUE, xmsDestination.ToString());
            var id = failed.GetStringProperty(HEADER_ORIGINALID);
            toSend.SetStringProperty(HEADER_ORIGINALID, id);
        }
Exemplo n.º 9
0
 public static int GetCurrentQueueDebth(XmsDestination destination)
 {
     var manager = new MQQueueManager(destination.Manager, destination.Channel, destination.ConnectionName);
     var queue = manager.AccessQueue(destination.Queue, MQC.MQOO_INQUIRE);
     int depth = queue.CurrentDepth;
     manager.Disconnect();
     manager.Close();
     return depth;
 }
Exemplo n.º 10
0
        public static int Purge(XmsDestination destination)
        {
            int i = 0;
            var factory = CreateConnectionFactory(destination);
            using (var connection = factory.CreateConnection())
            {
                using (ISession session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge))
                {
                    IDestination queue = session.CreateQueue(destination.Queue);
                    queue.SetIntProperty(XMSC.DELIVERY_MODE, XMSC.DELIVERY_NOT_PERSISTENT);

                    using (var consumer = session.CreateConsumer(queue))
                    {
                        connection.Start();
                        while (consumer.ReceiveNoWait() != null)
                        {
                            ++i;
                        }
                    }
                }
            }
            return i;
        }