Пример #1
0
        // Event Stream
        // ------------------------------------------------------------
        public static async Task EventStreamDemo(ITopicFactory factory)
        {
            var topic3 = factory.OpenTopic <Person>("event-stream-demo");

            await topic3.AppendAsync(new Person()
            {
                FullName = "Mad Dog"
            });

            var consumer3 = await topic3.CreateConsumerAsync("consumer3");

            Console.WriteLine($"Starting consumer at {consumer3.CurrentOffset}");

            var stream = consumer3.ToStreamEventObserable();

            // Partionable stream using message group meta data???
            //var input = stream.ToPartitionedStreamable(p => p.Payload.FullName, e=>e.EndTime);

            var input  = stream.ToStreamable();
            var output = input.Max(p => p.Age);

            var task = stream.StartObserving();

            Console.WriteLine("Output =");
            output.ToStreamEventObservable().ForEachAsync(e => Console.WriteLine(e)).Wait();
        }
 public ExecutionService(IRouteRepository routeRepository, IRequestRepository requestRepository, ITopicFactory topicFactory, IResponsePipeline responsePipeline, ITraceContext traceContext)
 {
     _routeRepository   = routeRepository;
     _requestRepository = requestRepository;
     _topicFactory      = topicFactory;
     _responsePipeline  = responsePipeline;
     _traceContext      = traceContext;
 }
Пример #3
0
        public TopicDispatcher(ITopicFactory <T> topicFactory)
        {
            if (topicFactory == null)
            {
                throw new ArgumentNullException(nameof(topicFactory));
            }

            _client = topicFactory.Create();
        }
        public BusConfigurationBuilder(IQueueFactory queueFactory, ITopicFactory topicFactory, ISubscriptionFactory subscriptionFactory)
        {
            _queueFactory        = queueFactory;
            _topicFactory        = topicFactory;
            _subscriptionFactory = subscriptionFactory;

            _queuesRequiringCreation = new List <IQueueInstance>();
            _eventsRequiringCreation = new List <Type>();
            _eventSubscriptions      = new List <EventSubscription>();
        }
Пример #5
0
 public Connection(ConnectionState state, ITopicFactory topicFactory)
 {
     if (state == null)
     {
         throw new ArgumentNullException(nameof(state));
     }
     if (topicFactory == null)
     {
         throw new ArgumentNullException(nameof(topicFactory));
     }
     _state        = state;
     _topicFactory = topicFactory;
 }
Пример #6
0
        public static async Task <Topics> ForAsync(ITopicFactory topicFactory, ICollection <Type> eventTypes)
        {
            var handlerTasks = eventTypes
                               .Select(topicFactory.From)
                               .ToList();

            await Task.WhenAll(handlerTasks);

            var taskResults = handlerTasks
                              .Select(task => task.Result)
                              .ToList();

            return(new Topics(taskResults));
        }
Пример #7
0
        /// <summary>Constructor</summary>
        /// <param name="agentId">The string name that uniquely identifies this agent in SIF Zones.
        /// This string is used as the <c>SourceId</c> in all SIF message
        /// headers created by the agent.
        /// </param>
        public Agent(string agentId)
        {
            if (agentId == null || agentId.Trim().Length == 0)
            {
                AdkUtils._throw
                    (new ArgumentException("Agent ID cannot be null or a blank string"), Log);
            }

            fSourceId = agentId;

            ObjectFactory factory = ObjectFactory.GetInstance();

            fZoneFactory  = (IZoneFactory)factory.CreateInstance(ObjectFactory.ADKFactoryType.ZONE, this);
            fTopicFactory = (ITopicFactory)factory.CreateInstance(ObjectFactory.ADKFactoryType.TOPIC, this);

            fTransportManager = new TransportManagerImpl();
        }
Пример #8
0
        public ResponsePipeline(ITopicFactory topicFactory)
        {
            // Since we're in a constructor, we can't use the await keyword, so we'll wait the old fashioned synchonous way.
            // The clientTask.Wait() is a blocking call. This call doesn't actually create the subscription, we do that on
            // pre-application initialization, since it's faster to do it once for the whole app up-front, instead of lazily
            // somwhere buried in a constructor, plus doing it lazily causes a dead-lock.
            var requestSubscriptionName = string.Format(Settings.ServiceBusResponseSubscriptionNameFormat, Environment.MachineName);
            var clientTask = topicFactory.CreateSubscriptionClientAsync(Settings.ServiceBusResponseTopicName, requestSubscriptionName);

            clientTask.Wait();

            // Do a quick check to ensure that the task didn't throw an exception and wasn't cancelled.
            if (clientTask.IsFaulted || clientTask.IsCanceled)
            {
                throw new ServiceBusException($"Failed to create and subscribe to the response topic for subscription '{requestSubscriptionName}'.", clientTask.Exception);
            }

            // Store the result in a local field as we don't want it to be garbage collected.
            _responseSubscription = clientTask.Result;

            // We only get one shot at processing the message, because the SubscriptionClient is set to ReceiveAndDelete.
            // This means that we don't have to call Complete() or Abandon() on messages, and also means we only need
            // one call to service bus to handle a message. We are publishing the message into an observable sequence
            // which will ensure only one thread handles the message at a time (even if there are multiple subscribers
            // to the observable sequence), but we'll set the MaxConcurrentCalls to something greater than 1, because the
            // observable sequence will hold the messages in memory while they are waiting to be processed. The
            // combination of these qualities means we can essentially prefetch messages while we are processing a
            // message. This does create multiple threads for each message, but the observable sequence will synchronize
            // them all back to the same thread. It's a small price to pay for prefetching ability.
            var options = new OnMessageOptions
            {
                AutoComplete       = true,
                MaxConcurrentCalls = 5  // Drain 5 at a time into memory, so we can do a bit of prefetching.
            };

            // Using the OnMessage delegate will handle the internal polling (or sockets, depending on mode) for us.
            // When we receive a message, we'll push it through the observable sequence. The OnNext() call will block
            // until all subscriptions have received the message, but we don't have any heavy processing happening, so
            // it's not a big deal and we are using ReceiveAndDelete anyways, so it doesn't matter how long the OnNext()
            // call takes.
            _responseSubscription.OnMessage(bm =>
            {
                _responseMessages.OnNext(bm);
            }, options);
        }
Пример #9
0
 public Server(ITopicFactory topicFactory, ITopicsConfigurationStorage topicsConfigurationStorage)
 {
     this.topicFactory = topicFactory;
     this.topicsConfigurationStorage = topicsConfigurationStorage;
     topics = new Dictionary <string, ITopicManagement>();
 }
Пример #10
0
        /// <summary>
        /// 實例化
        /// </summary>
        /// <param name="topicFactory"></param>
        public TopicHelper(ITopicFactory topicFactory)
        {
            Guard.ArgumentNotNull(topicFactory, "topicFactory");

            TopicFactory = topicFactory;
        }
Пример #11
0
 public TestEventHandler(IEventRepository eventRepository, ITopicFactory topicFactory)
     : base(eventRepository, topicFactory)
 {
 }
Пример #12
0
 protected PublishingEventHandler(IEventRepository repository, ITopicFactory topicFactory)
 {
     _repository   = repository;
     _topicFactory = topicFactory;
 }
Пример #13
0
        /// <summary>Constructor</summary>
        /// <param name="agentId">The string name that uniquely identifies this agent in SIF Zones.
        /// This string is used as the <c>SourceId</c> in all SIF message
        /// headers created by the agent.
        /// </param>
        public Agent( string agentId )
        {
            if ( agentId == null || agentId.Trim().Length == 0 )
            {
                AdkUtils._throw
                    ( new ArgumentException( "Agent ID cannot be null or a blank string" ), Log );
            }

            fSourceId = agentId;

            ObjectFactory factory = ObjectFactory.GetInstance();
            fZoneFactory = (IZoneFactory) factory.CreateInstance( ObjectFactory.ADKFactoryType.ZONE, this );
            fTopicFactory = (ITopicFactory) factory.CreateInstance( ObjectFactory.ADKFactoryType.TOPIC, this );

            fTransportManager = new TransportManagerImpl();
        }