Ejemplo n.º 1
0
        public PulsarSourceActor(ClientConfigurationData client, ReaderConfigurationData <T> readerConfiguration, IActorRef clientActor, IActorRef lookup, IActorRef cnxPool, IActorRef generator, long fromOffset, long toOffset, bool isLive, ISchema <T> schema)
        {
            _scheduler = Context.System.Scheduler.Advanced;
            _toOffset  = toOffset;
            _parent    = Context.Parent;
            _lastEventMessageOffset = fromOffset;
            var       topicName    = TopicName.Get(readerConfiguration.TopicName);
            IActorRef stateA       = Context.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}");
            var       subscription = "player-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10);

            if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix))
            {
                subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription;
            }

            ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>();

            consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName);
            consumerConfiguration.SubscriptionName  = subscription;
            consumerConfiguration.SubscriptionType  = SubType.Exclusive;
            consumerConfiguration.SubscriptionMode  = SubscriptionMode.NonDurable;
            consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize;
            consumerConfiguration.ReadCompacted     = readerConfiguration.ReadCompacted;
            consumerConfiguration.StartMessageId    = readerConfiguration.StartMessageId;

            if (readerConfiguration.ReaderName != null)
            {
                consumerConfiguration.ConsumerName = readerConfiguration.ReaderName;
            }

            if (readerConfiguration.ResetIncludeHead)
            {
                consumerConfiguration.ResetIncludeHead = true;
            }

            consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction;
            if (readerConfiguration.CryptoKeyReader != null)
            {
                consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader;
            }

            if (readerConfiguration.KeyHashRanges != null)
            {
                consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray());
            }

            var partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName);
            var consumerId   = generator.Ask <long>(NewConsumerId.Instance).GetAwaiter().GetResult();

            _child = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateA, clientActor, lookup, cnxPool, generator, readerConfiguration.TopicName, consumerConfiguration, Context.System.Scheduler.Advanced, partitionIdx, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, client)));
            _child.Tell(Connect.Instance);
            if (isLive)
            {
                LiveConsume();
            }
            else
            {
                Consume();
            }
        }
Ejemplo n.º 2
0
        public ReaderActor(long consumerId, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData)
        {
            _generator = idGenerator;
            var subscription = "reader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10);

            if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix))
            {
                subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription;
            }

            ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>();

            consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName);
            consumerConfiguration.SubscriptionName  = subscription;
            consumerConfiguration.SubscriptionType  = SubType.Exclusive;
            consumerConfiguration.SubscriptionMode  = SubscriptionMode.NonDurable;
            consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize;
            consumerConfiguration.ReadCompacted     = readerConfiguration.ReadCompacted;

            // Reader doesn't need any batch receiving behaviours
            // disable the batch receive timer for the ConsumerImpl instance wrapped by the ReaderImpl
            consumerConfiguration.BatchReceivePolicy = _disabledBatchReceivePolicy;

            if (readerConfiguration.StartMessageId != null)
            {
                consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId;
            }


            if (readerConfiguration.ReaderName != null)
            {
                consumerConfiguration.ConsumerName = readerConfiguration.ReaderName;
            }

            if (readerConfiguration.ResetIncludeHead)
            {
                consumerConfiguration.ResetIncludeHead = true;
            }

            if (readerConfiguration.ReaderListener != null)
            {
                var readerListener = readerConfiguration.ReaderListener;
                consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener);
            }

            consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction;
            if (readerConfiguration.CryptoKeyReader != null)
            {
                consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader;
            }

            if (readerConfiguration.KeyHashRanges != null)
            {
                consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray());
            }

            int partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName);

            if (consumerConfiguration.ReceiverQueueSize == 0)
            {
                _consumer = Context.ActorOf(Props.Create(() => new ZeroQueueConsumer <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, schema, true, clientConfigurationData)));
            }
            else
            {
                _consumer = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, clientConfigurationData)));
            }
            Receive <HasReachedEndOfTopic>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <AcknowledgeCumulativeMessage <T> > (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <Messages.Consumer.Receive> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <Connect> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <MessageProcessed <T> > (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <HasMessageAvailable> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <GetTopic> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <IsConnected> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <SeekMessageId> (m => {
                _consumer.Tell(m, Sender);
            });
            Receive <SeekTimestamp> (m => {
                _consumer.Tell(m, Sender);
            });
        }
Ejemplo n.º 3
0
        public MultiTopicsReader(IActorRef state, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData)
        {
            _generator = idGenerator;
            var subscription = "multiTopicsReader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10);

            if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix))
            {
                subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription;
            }
            var consumerConfiguration = new ConsumerConfigurationData <T>();

            foreach (var topic in readerConfiguration.TopicNames)
            {
                consumerConfiguration.TopicNames.Add(topic);
            }

            consumerConfiguration.SubscriptionName  = subscription;
            consumerConfiguration.SubscriptionType  = SubType.Exclusive;
            consumerConfiguration.SubscriptionMode  = SubscriptionMode.NonDurable;
            consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize;
            consumerConfiguration.ReadCompacted     = readerConfiguration.ReadCompacted;

            if (readerConfiguration.ReaderListener != null)
            {
                var readerListener = readerConfiguration.ReaderListener;
                consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener);
            }
            if (readerConfiguration.StartMessageId != null)
            {
                consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId;
            }

            if (readerConfiguration.ReaderName != null)
            {
                consumerConfiguration.ConsumerName = readerConfiguration.ReaderName;
            }
            if (readerConfiguration.ResetIncludeHead)
            {
                consumerConfiguration.ResetIncludeHead = true;
            }
            consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction;
            if (readerConfiguration.CryptoKeyReader != null)
            {
                consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader;
            }
            if (readerConfiguration.KeyHashRanges != null)
            {
                consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray());
            }
            _consumer = Context.ActorOf(Props.Create(() => new MultiTopicsConsumer <T>(state, client, lookup, cnxPool, _generator, consumerConfiguration, listenerExecutor, schema, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, clientConfigurationData)));

            ReceiveAsync <SubscribeAndCreateTopicsIfDoesNotExist>(async subs =>
            {
                _sender = Sender;
                await SubscribeAndCreateTopics(subs);
            });
            ReceiveAsync <Subscribe>(async sub =>
            {
                _sender = Sender;
                await SubscribeToTopic(sub);
            });
            Receive <HasReachedEndOfTopic>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <AcknowledgeCumulativeMessage <T> >(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <MessageProcessed <T> >(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <Messages.Consumer.Receive>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <HasMessageAvailable>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <GetTopic>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <IsConnected>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <SeekMessageId>(m => {
                _consumer.Tell(m, Sender);
            });
            Receive <SeekTimestamp>(m => {
                _consumer.Tell(m, Sender);
            });
            ReceiveAny(m => {
                _consumer.Tell(m, Sender);
            });
        }