Ejemplo n.º 1
0
        /// <summary>
        ///   Create a WMQ connection factory and set relevant properties.
        /// </summary>
        /// <returns>A connection factory</returns>
        public static IConnectionFactory CreateConnectionFactory(XmsAddress 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.Host.HostName);
            cf.SetIntProperty(XMSC.WMQ_PORT, destination.Host.Port);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, destination.Host.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.Host.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);
        }
 public void Init(Address address, bool transactional)
 {
     this.address = address.ToXmsAddress();
     if (PurgeOnStartup)
         XmsUtilities.Purge(this.address);
     this.useTransactions = transactional;
     this.consumerProducer = new XmsConsumerProvider(transactional);
 }
Ejemplo n.º 3
0
 public static int GetCurrentQueueDebth(XmsAddress address)
 {
     var manager = new MQQueueManager(address.Host.Manager, address.Host.Channel, address.Host.ConnectionName);
     var queue = manager.AccessQueue(address.Queue, MQC.MQOO_INQUIRE);
     int depth = queue.CurrentDepth;
     manager.Disconnect();
     manager.Close();
     return depth;
 }
 private Pool<XmsPooledConsumer> CreatePool(XmsAddress address)
 {
     log.Info("Going to create new consumer pool for address {0}".FormatWith(address));
     //TODO: make this configurable
     var store = new StackStore<XmsPooledConsumer>(60.Seconds(), 30.Seconds());
     var pool = new Pool<XmsPooledConsumer>(10, p =>
         {
             log.Info("Going to create new plain consumer for address {0}".FormatWith(address));
             var consumer = new XmsConsumer(address, transactional);
             var pooled = new XmsPooledConsumer(p, consumer);
             return pooled;
         }, store);
     return pool;
 }
Ejemplo n.º 5
0
        public static int Purge(XmsAddress 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;
        }
        public IXmsConsumer GetConsumer(XmsAddress address)
        {
            Pool<XmsPooledConsumer> pool;
            if (!poolsByDestination.TryGetValue(address, out pool))
            {
                lock (locker)
                {
                    pool = poolsByDestination.GetOrAdd(address, CreatePool);
                }
            }

            if (IsInTransaction && transactional)
            {
                log.Debug("Detected transaction scope on transactional consumer provider. Using transaction scope allocation.");
                var transaction = Transaction.Current;
                var key = "{0}|{1}".FormatWith(transaction.TransactionInformation.LocalIdentifier, address);

                if (!threadAllocatedConsumers.ContainsKey(key))
                {
                    log.Debug("Allocating consumer to a transaction scope {0}".FormatWith(key));
                    var pooled = pool.Acquire();
                    threadAllocatedConsumers[key] = pooled;
                    XmsPooledConsumer _;
                    transaction.TransactionCompleted += (s, e) =>
                        {
                            log.Debug("Dealocating consumer from transaction scope {0}.".FormatWith(key));
                            threadAllocatedConsumers.TryRemove(key, out _);
                            pooled.Dispose();
                        };
                }

                return threadAllocatedConsumers[key];
            }

            log.Debug("Acquiring consumer without the transaction scope.");
            return pool.Acquire();
        }
Ejemplo n.º 7
0
 public XmsProducer(XmsAddress address, bool transactional)
 {
     this.address = address;
     this.transactional = transactional;
 }
Ejemplo n.º 8
0
 protected bool Equals(XmsAddress other)
 {
     return string.Equals(Queue, other.Queue) && Equals(Host, other.Host);
 }
Ejemplo n.º 9
0
 public XmsConsumer(XmsAddress address, bool transactional)
 {
     this.address = address;
     this.transactional = transactional;
 }