Esempio n. 1
0
 public MessageSource(Lazy <IConnection> lazyConnection,
                      IEnumerable <IMessageDeserializer <TMessage> > deserializers,
                      IDestination destination,
                      AcknowledgementMode mode = AcknowledgementMode.AutoAcknowledge,
                      string selector          = null,
                      Func <IDictionary, bool> propertyFilter = null)
 {
     _deserializers  = deserializers.ToDictionary(d => d.GetTypeName());
     _lazyConnection = lazyConnection;
     _destination    = destination;
     _mode           = mode == AcknowledgementMode.ClientAcknowledge ? Apache.NMS.AcknowledgementMode.ClientAcknowledge : Apache.NMS.AcknowledgementMode.AutoAcknowledge;
     _selector       = selector;
     _propertyFilter = propertyFilter;
 }
Esempio n. 2
0
 /// <summary>
 /// Creates a new session to work on this connection
 /// </summary>
 public Apache.NMS.ISession CreateSession(
     Apache.NMS.AcknowledgementMode mode)
 {
     try
     {
         bool isTransacted =
             (mode == Apache.NMS.AcknowledgementMode.Transactional);
         return(XMSConvert.ToNMSSession(
                    this.xmsConnection.CreateSession(
                        isTransacted, XMSConvert.ToAcknowledgeMode(mode))));
     }
     catch (Exception ex)
     {
         ExceptionUtil.WrapAndThrowNMSException(ex);
         return(null);
     }
 }
Esempio n. 3
0
        public MessageSource(Lazy <IConnection> lazyConnection,
                             IEnumerable <IMessageDeserializer <TMessage> > deserializers,
                             IDestination destination,
                             AcknowledgementMode mode = AcknowledgementMode.AutoAcknowledge,
                             string selector          = null,
                             Func <IDictionary, bool> propertyFilter = null,
                             bool noLocal = false)
        {
            _deserializers  = deserializers.ToDictionary(d => d.GetTypeName());
            _lazyConnection = lazyConnection;
            _destination    = destination;
            _mode           = mode == AcknowledgementMode.ClientAcknowledge ? Apache.NMS.AcknowledgementMode.ClientAcknowledge : Apache.NMS.AcknowledgementMode.AutoAcknowledge;
            _selector       = selector;
            _propertyFilter = propertyFilter;
            _noLocal        = noLocal;

            var messages = Observable.Create <TMessage>(observer =>
            {
                var session = _lazyConnection.Value.CreateSession(_mode);

                var subscription = session
                                   .ToObservable(_destination, _selector, _noLocal)
                                   .Where(PassesFilter)
                                   .Select(message => new { message, deserializer = GetDeserializer(message) })
                                   .Where(msg => msg.deserializer != null)
                                   .Select(msg => DeserializeAndAcknowledge(msg.message, msg.deserializer))
                                   .Subscribe(observer);

                return(Disposable.Create(() =>
                {
                    subscription.Dispose();
                    session.Close();
                    session.Dispose();
                }));
            });

            // Can only do this optimization if we're on a topic
            if (_destination.DestinationType == DestinationType.Topic)
            {
                messages = messages
                           .PublishRefCountRetriable();
            }

            Messages = messages;
        }