private void AddConfigurationAndGatewayServices(IServiceCollection services) { var cosmosDBConfiguration = new CosmosDBConfiguration(); Configuration.Bind("CosmosDB", cosmosDBConfiguration); services.AddSingleton(cosmosDBConfiguration); var eventGridConfiguration = new EventGridConfiguration(); Configuration.Bind("EventGrid", eventGridConfiguration); services.AddSingleton(eventGridConfiguration); var websocketConfiguration = new WebsocketConfiguration(); Configuration.Bind("Websocket", websocketConfiguration); services.AddSingleton(websocketConfiguration); services.AddSingleton <IDecisionChannel, DecisionChannelRx>(); services.AddSingleton <IPerceptionChannel, PerceptionChannelRx>(); if (eventGridConfiguration.Enabled) { services.AddSingleton(s => new EventGridClient(new TopicCredentials(eventGridConfiguration.PersonProfileContextPerceptionTopicKey))); services.AddSingleton <PerceptionChannelAdapterEventGrid>(); } else { // Individual components and their dependencies, seemlessly replaced by Azure functions in the cloud services.AddSingleton(s => new DocumentClient(new Uri(cosmosDBConfiguration.AccountEndpoint), cosmosDBConfiguration.AccountKey)); services.AddSingleton <PersonComponent>(); services.AddSingleton <IPersonRepository, PersonRepositoryCosmosDb>(); } }
public static void AddEventGrid(this IServiceCollection services) { var endpoint = Environment.GetEnvironmentVariable("EventGrid__Endpoint", EnvironmentVariableTarget.Process); var topicKey = Environment.GetEnvironmentVariable("EventGrid__TopicKey", EnvironmentVariableTarget.Process); var config = new EventGridConfiguration() { Endpoint = endpoint, TopicKey = topicKey }; services.AddSingleton(config); services.AddSingleton <IEventGridService, EventGridService>(); }
public EventGridPublishingHandlerTests() { EventGridConfigurationOptionsMonitor = A.Fake <IOptionsMonitor <EventGridConfiguration> >(); EventGridConfiguration = new EventGridConfiguration(); A.CallTo(() => EventGridConfigurationOptionsMonitor.CurrentValue) .Returns(EventGridConfiguration); EventGridContentClient = A.Fake <IEventGridContentClient>(); SyncNameProvider = A.Fake <ISyncNameProvider>(); UserId = "C7FE81FB-CF2B-4897-ABE9-1EB931A31371"; A.CallTo(() => SyncNameProvider.GetEventIdPropertyValue( A <JObject> ._, A <IContentItemVersion> ._)).Returns(UserId); PublishedContentItemVersion = A.Fake <IPublishedContentItemVersion>(); PreviewContentItemVersion = A.Fake <IPreviewContentItemVersion>(); NeutralEventContentItemVersion = A.Fake <INeutralEventContentItemVersion>(); Logger = A.Fake <ILogger <EventGridPublishingHandler> >(); EventGridPublishingHandler = new EventGridPublishingHandler( EventGridConfigurationOptionsMonitor, EventGridContentClient, SyncNameProvider, PublishedContentItemVersion, PreviewContentItemVersion, NeutralEventContentItemVersion, Logger); OrchestrationContext = A.Fake <IOrchestrationContext>(); ContentItem = new ContentItem { ContentType = "ContentType", ContentItemVersionId = "ContentItemVersionId", DisplayText = "DisplayText", Author = "Author" }; A.CallTo(() => OrchestrationContext.ContentItem) .Returns(ContentItem); }
/// <summary> /// Adds services to enable publishing of content events to Azure Event Grid. /// </summary> /// <remarks> /// Policy notes: /// We don't add a circuit-breaker (but we might later). /// We could add knowledge of CloudError to policy, but we don't as errors resulting in CloudError's are /// probably our fault (with the event contents), as opposed to transient network/http errors. /// We might want to change the Handler lifetime from the default of 2 minutes, using /// .SetHandlerLifetime(TimeSpan.FromMinutes(3)); /// it's a balance between keeping sockets open and latency in handling dns updates. /// </remarks> public static void AddEventGridPublishing(this IServiceCollection services, IConfiguration configuration) { var eventGridSection = configuration.GetSection("EventGrid"); services.Configure <EventGridConfiguration>(eventGridSection); //todo: check config for null and throw meaningful exceptions EventGridConfiguration eventGridConfig = eventGridSection.Get <EventGridConfiguration>(); // publishing an event should be quick, so set the timeout low var timeoutPolicy = Policy.TimeoutAsync <HttpResponseMessage>(5); foreach (EventGridTopicConfiguration eventGridTopicConfig in eventGridConfig.Topics) { var delay = Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: 5); services.AddHttpClient(eventGridTopicConfig.ContentType, client => { client.BaseAddress = new Uri(eventGridTopicConfig.TopicEndpoint !); client.DefaultRequestHeaders.Add("aeg-sas-key", eventGridTopicConfig.AegSasKey !); })
public PerceptionChannelAdapterEventGrid(EventGridClient eventGridClient, EventGridConfiguration eventGridConfiguration) { _eventGridClient = eventGridClient; _topicHostName = new Uri(eventGridConfiguration.PersonProfileContextPerceptionTopicUrl).Host; }
public MessageService(IOptions <EventGridConfiguration> options) { _config = options.Value; }
public EventGridMessagingHelper(IConfiguration configuration) { config = new EventGridConfiguration(); configuration.Bind("EventGrid", this.config); }