protected override async Task Terminate(IIncomingPhysicalMessageContext context) { var message = context.Message; var timeoutId = message.Headers["Timeout.Id"]; var timeoutData = await persister.Peek(timeoutId, context.Extensions).ConfigureAwait(false); if (timeoutData == null) { return; } var sendOptions = new DispatchOptions(new UnicastAddressTag(timeoutData.Destination), dispatchConsistency); timeoutData.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); timeoutData.Headers["NServiceBus.RelatedToTimeoutId"] = timeoutData.Id; await dispatcher.Dispatch(new[] { new TransportOperation(new OutgoingMessage(message.MessageId, timeoutData.Headers, timeoutData.State), sendOptions) }, context.Extensions).ConfigureAwait(false); var timeoutRemoved = await persister.TryRemove(timeoutId, context.Extensions).ConfigureAwait(false); if (!timeoutRemoved) { // timeout was concurrently removed between Peek and TryRemove. Throw an exception to rollback the dispatched message if possible. throw new Exception($"timeout '{timeoutId}' was concurrently processed."); } }
public async Task HandleMessage(QueueTMessage message) { if (!message.Properties.TryGetValue(NotificationMessage.TopicPropertyKey, out var topic)) { throw new MessageProcessingException(message: $"Topic name not present"); } var notificationDefinition = _notificationRegistry.GetNotificationByTopic(topic); var subscriptions = _notificationRegistry.GetSubscriptions(notificationDefinition); if (0 == subscriptions.Length) { return; } JObject argument = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(message.EncodedBody)) as JObject; var properties = argument.Properties().ToArray(); foreach (var subscription in subscriptions) { object taskArgument = null; var options = new DispatchOptions { Queue = subscription.TaskQueue }; taskArgument = new Dictionary <string, object> { { subscription.MessageParameter.Name, argument } }; await _taskService.DelayAsync(subscription.Method, taskArgument, options); } }
public void Should_use_the_non_durable_setting() { var options = new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default, new List <DeliveryConstraint> { new NonDurableDelivery() }); Assert.False(MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string>(), new byte[0]), options).Recoverable); Assert.True(MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string>(), new byte[0]), new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default, new List <DeliveryConstraint>())).Recoverable); }
// Subscriptions public async Task NotifyAsync(Enum notificationEnum, object value, DispatchOptions options = null) { var notificationDefinition = _notificationRegistry.GetNotificationByEnum(notificationEnum); options = options ?? new DispatchOptions(); options.Properties[NotificationMessage.TopicPropertyKey] = notificationDefinition.Topic; options.Queue = options.Queue ?? _options.DefaultQueueName; await _messageDispatcher.SendMessageAsync(NotificationMessage.MessageType, value, options); }
public void Should_use_the_TTBR_in_the_send_options_if_set() { var options = new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default, new List <DeliveryConstraint> { new DiscardIfNotReceivedBefore(TimeSpan.FromDays(1)) }); var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string>(), new byte[0]), options); Assert.AreEqual(TimeSpan.FromDays(1), message.TimeToBeReceived); }
public void Should_convert_a_message_back_even_if_special_characters_are_contained_in_the_headers() { var expected = $"Can u see this '{(char) 0x19}' character."; var options = new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default); var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), options); var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
public T CreateProxy <T>(ProxyOptions options, IInvokeFilter[] filters) where T : class { var dispatcher = SeifApplication.AppEnv.GlobalConfiguration.InvokeDispatcher; var dispatchOptions = new DispatchOptions { ServiceKind = options.ServiceKind, Stragedy = options.DispathStragedy }; var invoker = dispatcher.Dispatch <T>(dispatchOptions); ProxyGenerator generator = new ProxyGenerator(); return(generator.CreateInterfaceProxyWithoutTarget <T>(new CallingInterceptor <T>(invoker, filters))); }
public async Task RawSending() { IDispatchMessages dispatcher = null; #region DispatcherRawSending var headers = new Dictionary<string, string>(); var outgoingMessage = new OutgoingMessage("MessageId", headers, new byte[] { }); var constraints = new[] { new NonDurableDelivery() }; UnicastAddressTag address = new UnicastAddressTag("Destination"); var options = new DispatchOptions(address, DispatchConsistency.Default, constraints); TransportOperation transportOperation = new TransportOperation(outgoingMessage, options); await dispatcher.Dispatch(new[] { transportOperation }, new ContextBag()); #endregion }
public void Should_convert_message_headers_that_contain_nulls_at_the_end() { var expected = "Hello World"; var options = new DispatchOptions(new UnicastAddressTag("destination"), DispatchConsistency.Default); Console.Out.WriteLine(sizeof(char)); var message = MsmqUtilities.Convert(new OutgoingMessage("message id", new Dictionary <string, string> { { "NServiceBus.ExceptionInfo.Message", expected } }, new byte[0]), options); var bufferWithNulls = new byte[message.Extension.Length + 10 * sizeof(char)]; Buffer.BlockCopy(message.Extension, 0, bufferWithNulls, 0, bufferWithNulls.Length - 10 * sizeof(char)); message.Extension = bufferWithNulls; var headers = MsmqUtilities.ExtractHeaders(message); Assert.AreEqual(expected, headers["NServiceBus.ExceptionInfo.Message"]); }
public IInvoker Dispatch <T>(DispatchOptions options) { //if (options.ServiceKind == ServiceKind.Local) //{ // return new LocalInvoker<T>(null); //} var metta = SeifApplication.AppEnv.GlobalConfiguration.Registry.GetServiceRegistryMetta <T>(); if (metta == null || !metta.Any()) { throw new Exception("Invoker Metta not exists"); } var selectedInvokeMetta = metta.Length == 1 ? metta[0] : options.Stragedy.Select(typeof(T), metta); var invokerFactory = SeifApplication.AppEnv.GlobalConfiguration.InvokerFactory;//SeifApplication.Resolve<IInvokerFactory>(); return(invokerFactory.CreateInvoker(selectedInvokeMetta)); }
/// <summary> /// Routes the teleport request to the right handler. /// Options: <para /> /// RequireProcessing: Will add to the teleport queue;<para/> /// DiscardIfProcessing: Will reject the teleport if the manager is busy; <para/> /// RequireImmediateProcessing: Will process it immediately, bypassing the queue. <para /> /// </summary> /// <param name="teleportObject"> The object to teleport.</param> /// <param name="destination"> Where to teleport the object to.</param> /// <param name="options"> Whether to discard, wait, or process immediately.</param> /// <param name="teleportGate"> OPTIONAL. Provide for ONE WAY TELEPORTS that have orientation.</param> public void Dispatch(GameObject teleportObject, Vector3 destination, DispatchOptions options, GameObject teleportGate = null) { if (teleportGate != null) { DispatchRequireImmediateProcesingWithOrientation(teleportObject, teleportGate); } else { switch (options) { case DispatchOptions.DiscardIfProcessing: DispatchDiscardIfProcessing(teleportObject, destination); break; case DispatchOptions.RequireProcessing: DispatchRequireProcessing(teleportObject, destination); break; case DispatchOptions.RequireImmediateProcessing: DispatchRequireImmediateProcessing(teleportObject, destination); break; } } }
protected override async Task Terminate(IIncomingPhysicalMessageContext context) { var message = context.Message; var sagaId = Guid.Empty; string sagaIdString; if (message.Headers.TryGetValue(Headers.SagaId, out sagaIdString)) { sagaId = Guid.Parse(sagaIdString); } if (message.Headers.ContainsKey(TimeoutManagerHeaders.ClearTimeouts)) { if (sagaId == Guid.Empty) { throw new InvalidOperationException("Invalid saga id specified, clear timeouts is only supported for saga instances"); } await persister.RemoveTimeoutBy(sagaId, context.Extensions).ConfigureAwait(false); } else { string expire; if (!message.Headers.TryGetValue(TimeoutManagerHeaders.Expire, out expire)) { throw new InvalidOperationException("Non timeout message arrived at the timeout manager, id:" + message.MessageId); } var destination = message.GetReplyToAddress(); string routeExpiredTimeoutTo; if (message.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo)) { destination = routeExpiredTimeoutTo; } var data = new TimeoutData { Destination = destination, SagaId = sagaId, State = message.Body, Time = DateTimeExtensions.ToUtcDateTime(expire), Headers = message.Headers, OwningTimeoutManager = owningTimeoutManager }; if (data.Time.AddSeconds(-1) <= DateTime.UtcNow) { var sendOptions = new DispatchOptions(new UnicastAddressTag(data.Destination), DispatchConsistency.Default); var outgoingMessage = new OutgoingMessage(message.MessageId, data.Headers, data.State); await dispatcher.Dispatch(new[] { new TransportOperation(outgoingMessage, sendOptions) }, context.Extensions).ConfigureAwait(false); return; } await persister.Add(data, context.Extensions).ConfigureAwait(false); poller.NewTimeoutRegistered(data.Time); } }
private async Task <TaskMessage> _DelayAsync(MethodCallExpression methodExpression, DispatchOptions options = null) { if (null == methodExpression) { throw new ArgumentException("Expression must be a method call"); } var definition = GetTaskDefinition(methodExpression.Method); var arguments = definition.CreateArgumentsFromCall(methodExpression); return(await DispatchAsync(definition, arguments, options)); }
public async Task <TaskMessage> DelayAsync(MethodInfo methodInfo, object arguments, DispatchOptions options = null) { if (methodInfo == null) { throw new ArgumentNullException(nameof(methodInfo)); } var definition = GetTaskDefinition(methodInfo); return(await DispatchAsync(definition, arguments, options)); }
public async Task <TaskMessage> DelayAsync(string taskName, object arguments, DispatchOptions options = null) { var definition = GetTaskDefinition(taskName); return(await DispatchAsync(definition, arguments, options)); }
private async Task <TaskMessage> DispatchAsync(TaskDefinition definition, object arguments, DispatchOptions options = null) { options = options ?? new DispatchOptions(); options.Queue = options.Queue ?? definition.QueueName ?? _taskOptions.DefaultQueueName; options.Properties[TaskNamePropertyKey] = definition.Name; var message = await _messageDispatcher.SendMessageAsync(MessageType, arguments, options); return(new TaskMessage { Name = definition.Name }); }
public async Task <TaskMessage> DelayAsync <T>(Expression <Func <T, Task> > expression, DispatchOptions options = null) => await _DelayAsync(expression?.Body as MethodCallExpression, options);
public async Task NotifyAsync <T>(Enum topicEnumValue, T value, DispatchOptions dispatchOptions = null) => await NotifyAsync(topicEnumValue, value as object, dispatchOptions);