async Task UpdateCaches(EndpointInstance instanceName, Type[] handledTypes, Type[] publishedTypes) { var newInstanceMap = BuildNewInstanceMap(instanceName); var newEndpointMap = BuildNewEndpointMap(instanceName.Endpoint, handledTypes, endpointMap); var newPublisherMap = BuildNewPublisherMap(instanceName, publishedTypes, publisherMap); LogChangesToEndpointMap(endpointMap, newEndpointMap); LogChangesToInstanceMap(instanceMap, newInstanceMap); var toSubscribe = LogChangesToPublisherMap(publisherMap, newPublisherMap).ToArray(); #region AddOrReplace routingTable.AddOrReplaceRoutes("AutomaticRouting", newEndpointMap.Select( x => new RouteTableEntry(x.Key, UnicastRoute.CreateFromEndpointName(x.Value))).ToList()); publishers.AddOrReplacePublishers("AutomaticRouting", newPublisherMap.Select( x => new PublisherTableEntry(x.Key, PublisherAddress.CreateFromEndpointName(x.Value))).ToList()); endpointInstances.AddOrReplaceInstances("AutomaticRouting", newInstanceMap.SelectMany(x => x.Value).ToList()); #endregion instanceMap = newInstanceMap; endpointMap = newEndpointMap; publisherMap = newPublisherMap; foreach (var type in toSubscribe.Intersect(messageTypesHandledByThisEndpoint)) { await messageSession.Subscribe(type) .ConfigureAwait(false); } }
/// <summary> /// Subscribes to receive published messages of the specified type. /// This method is only necessary if you turned off auto-subscribe. /// </summary> /// <param name="session">Object being extended.</param> /// <param name="messageType">The type of message to subscribe to.</param> public static Task Subscribe(this IMessageSession session, Type messageType) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNull(nameof(messageType), messageType); return(session.Subscribe(messageType, new SubscribeOptions())); }
/// <summary> /// Subscribes to receive published messages of the specified type. /// This method is only necessary if you turned off auto-subscribe. /// </summary> /// <param name="session">Object being extended.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param> /// <param name="messageType">The type of message to subscribe to.</param> public static Task Subscribe(this IMessageSession session, Type messageType, CancellationToken cancellationToken = default) { Guard.AgainstNull(nameof(session), session); Guard.AgainstNull(nameof(messageType), messageType); return(session.Subscribe(messageType, new SubscribeOptions(), cancellationToken)); }
protected override async Task OnStart(IMessageSession session) { foreach (var eventType in messagesHandledByThisEndpoint) { await session.Subscribe(eventType).ConfigureAwait(false); Logger.DebugFormat("Auto subscribed to event {0}", eventType); } }
protected override async Task OnStart(IMessageSession session) { foreach (var eventType in messagesHandledByThisEndpoint) { await session.Subscribe(eventType).ConfigureAwait(false); Logger.DebugFormat("Auto subscribed to event {0}", eventType); } }
static async Task SubscribeToEvent(IMessageSession session, Type eventType) { try { await session.Subscribe(eventType).ConfigureAwait(false); Logger.DebugFormat("Auto subscribed to event {0}", eventType); } catch (Exception e) when(!(e is QueueNotFoundException)) { Logger.Error($"AutoSubscribe was unable to subscribe to event '{eventType.FullName}': {e.Message}"); // swallow exception } }
protected override async Task OnStart(IMessageSession session) { // Subscribe to BulkMessage, because it wraps messages and is not used in a handler directly if (!_config.Passive) { await session.Subscribe <BulkMessage>().ConfigureAwait(false); } Logger.InfoEvent("Startup", "Starting on {Queue}", _instanceQueue); await session.Publish <EndpointAlive>(x => { x.Endpoint = _instanceQueue; x.Instance = Defaults.Instance; }).ConfigureAwait(false); // Don't stop the bus from completing setup ThreadPool.QueueUserWorkItem(_ => { _startupTasks.WhenAllAsync(x => x(_config)).Wait(); }); }
protected override Task OnStart(IMessageSession session, CancellationToken cancellationToken) { return(session.Subscribe <LocalEvent>(cancellationToken)); }
/// <summary> /// Subscribes to receive published messages of type T. /// This method is only necessary if you turned off auto-subscribe. /// </summary> /// <param name="session">Object being extended.</param> /// <typeparam name="T">The type of message to subscribe to.</typeparam> public static Task Subscribe <T>(this IMessageSession session) { Guard.AgainstNull(nameof(session), session); return(session.Subscribe(typeof(T), new SubscribeOptions())); }
static async Task SubscribeToEvent(IMessageSession session, Type eventType) { await session.Subscribe(eventType).ConfigureAwait(false); Logger.DebugFormat("Auto subscribed to event {0}", eventType); }
/// <summary> /// Subscribes to receive published messages of type T. /// This method is only necessary if you turned off auto-subscribe. /// </summary> /// <param name="session">Object being extended.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe.</param> /// <typeparam name="T">The type of message to subscribe to.</typeparam> public static Task Subscribe <T>(this IMessageSession session, CancellationToken cancellationToken = default) { Guard.AgainstNull(nameof(session), session); return(session.Subscribe(typeof(T), new SubscribeOptions(), cancellationToken)); }