Exemplo n.º 1
0
        private async Task <Container> GetDestinationContainer(ConsumerRouterSettings consumerRouterSettings, string topic)
        {
            if (consumerRouterSettings.IsIndividualTopicsRoutingEnabled)
            {
                if (consumerRouterSettings.WhiteListedTopies.Contains(topic))
                {
                    // Route these to specific container
                    // Make sure topic container exists
                    if (!CosmosClientPool.IsTopicExists(topic))
                    {
                        Database database = CosmosClientPool.GetCosmosClient(this.cosmosDBSettings.Consumer).GetDatabase(this.cosmosDBSettings.Consumer.Database);
                        // Create a new container in the same database.
                        Container container = await CosmosExtension.SetupCollectionAsync(database, topic, this.cosmosDBSettings.Consumer.PartitionKeyPath, this.cosmosDBSettings.Consumer.CreateIfContainerNotExists, this.cosmosDBSettings.Consumer.DeleteIfContainerExists);

                        CosmosClientPool.AddTopic(topic);
                        return(container);
                    }

                    return(CosmosClientPool.GetCosmosClient(this.cosmosDBSettings.Consumer).GetContainer(this.cosmosDBSettings.Consumer.Database, topic));
                }
            }

            // Default container
            return(CosmosClientPool.GetCosmosClient(this.cosmosDBSettings.Consumer).GetContainer(this.cosmosDBSettings.Consumer.Database, this.cosmosDBSettings.Consumer.Container));
        }
        public static ConsumerRouterSettings LoadCosmosConsumerRouterSettings(IConfigurationRoot configuration)
        {
            ConsumerRouterSettings cosmosConsumerRouterSettings = new ConsumerRouterSettings();

            cosmosConsumerRouterSettings.IsIndividualTopicsRoutingEnabled = bool.Parse(configuration["EnableIndividualTopicsRouting"]);
            cosmosConsumerRouterSettings.WhiteListedTopies = configuration["WhiteListedTopics"].Split(new char[] { '|' }).ToList();
            cosmosConsumerRouterSettings.Host = configuration["Host"];
            return(cosmosConsumerRouterSettings);
        }
Exemplo n.º 3
0
        public async Task WriteEvents(IReadOnlyCollection <EventDataModel> changes, ConsumerRouterSettings consumerRouterSettings)
        {
            foreach (EventDataModel item in changes)
            {
                Console.WriteLine($"\tReceived id: {item.id}, created time: {item.createdTime} , topic: {item.topic}, message: {item.message}");
                PartitionKey destinationPartitionkey = new PartitionKey(item.id);
                Container    destination             = await GetDestinationContainer(consumerRouterSettings, item.topic);

                Console.WriteLine($"\t sending it to account: {this.cosmosDBSettings.Consumer.Endpoint}, database: {this.cosmosDBSettings.Consumer.Database} , collection: {destination.Id}, topic: {item.topic}");
                await destination.CreateItemAsync <EventDataModel>(item, destinationPartitionkey);
            }
        }