Пример #1
0
        private void InitializeConsumer()
        {
            // TODO: Get settings from config file.
            var serializer = new JsonSerializer();
            var client     = SubscriptionClient.CreateFromConnectionString(settings.ConnectionString, "proto/events", "AllEvents");

            consumer = new TopicConsumer(client, serializer);
        }
Пример #2
0
        /// <summary>
        /// Create a new instance of <see cref="ITopicCollection"/> from an existing one
        /// </summary>
        /// <param name="topicCollection">Existing collection, seeding this one</param>
        /// <param name="topicConsumer">Context where this topic will be consumed</param>
        public TopicBuilder(ITopicCollection topicCollection, TopicConsumer topicConsumer)
        {
            TopicCollection = topicCollection;
            Consumer        = topicConsumer;

            _state = Consumer == TopicConsumer.Publisher
                ? (IBuilderState) new PublisherState(this)
                : new SubscriberState(this);

            if (Consumer == TopicConsumer.Publisher)
            {
                var validator = ValidatorFactory.GetPublishedTopicValidator();
                TopicCollection.ToList()
                .ForEach(validator.Validate);
            }
        }
Пример #3
0
        public static TopicConsumer <TKey, TValue> GetTopicConsumer <TKey, TValue>(
            IConsumerClient <TKey, TValue> client,
            ConsumerConnectionBuilder <TKey, TValue> cb,
            IServiceBusLogger logger
            )
        {
            var consumer = cb.Build();

            var topicConsumer = new TopicConsumer <TKey, TValue>(
                cb.Topic,
                cb.GetConsumerConfig(),
                consumer,
                client,
                logger
                );

            return(topicConsumer);
        }
Пример #4
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, TopicConsumer obj)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseCors("CORS");
            // app.UseHttpsRedirection();
            app.UseMvc();
        }
Пример #5
0
 /// <summary>
 /// Get an instance of a <see cref="ITopicBuilder"/> in the desired <paramref name="target"/> mode
 /// from an existing builder
 /// </summary>
 /// <param name="builder">Builder to convert</param>
 /// <param name="target">Mode in which converting the target</param>
 /// <returns>A new builder whose consumer is <paramref name="target"/></returns>
 /// <remarks>
 /// If the builder's consumer already is in <paramref name="target"/> mode, this will return a clone
 /// of the provided <paramref name="builder"/>
 /// </remarks>
 private static ITopicBuilder Convert(ITopicBuilder builder, TopicConsumer target)
 => builder.Consumer == target
         ? builder.Clone()
         : new TopicBuilder(builder.TopicCollection, target);
Пример #6
0
 /// <summary>
 /// Create a new <see cref="ITopicCollection"/> with a maximum capacity
 /// </summary>
 /// <param name="maxLevel">Maximum number of topics that the collection can contains</param>
 /// <param name="topicConsumer">Context where this topic will be consumed</param>
 public TopicBuilder(int maxLevel, TopicConsumer topicConsumer)
     : this(new TopicCollection(maxLevel), topicConsumer)
 {
 }
Пример #7
0
 /// <summary>
 /// Create a new <see cref="ITopicCollection"/>
 /// </summary>
 /// <param name="topicConsumer">Context where this topic will be consumed</param>
 /// <remarks>
 /// The maximum capacity will be <see cref="Mqtt.Topic.MaximumAllowedLevels"/>
 /// </remarks>
 public TopicBuilder(TopicConsumer topicConsumer)
     : this(Mqtt.Topic.MaximumAllowedLevels, topicConsumer)
 {
 }
Пример #8
0
 /// <summary>
 /// Create a new <see cref="ITopicBuilder"/> from an existing topic
 /// </summary>
 /// <param name="topic">
 /// <see cref="Topic"/> used for seeding the new <see cref="ITopicBuilder"/> instance
 /// </param>
 /// <param name="topicConsumer">Context where this topic will be consumed</param>
 /// <returns>A new <see cref="ITopicBuilder"/> instance seeded with the provided <see cref="Topic"/></returns>
 public static ITopicBuilder FromTopic(Topic topic, TopicConsumer topicConsumer)
 => new TopicBuilder(topic.Levels, topicConsumer)
 // Adding topics *after* having set the TopicConsumer property will ensure that no illegal topics has
 // been added in the builder
 .AddTopics(topic.ToArray());