/// <summary> /// Sends an object as a message, using the message type specified. If the object cannot be cast /// to the specified message type, an exception will be thrown. /// </summary> /// <param name="context">The consume context</param> /// <param name="message">The message object</param> /// <param name="destinationAddress">The destination address where the schedule message should be sent</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="messageType">The type of the message (use message.GetType() if desired)</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> ScheduleSend(this ConsumeContext context, Uri destinationAddress, DateTime scheduledTime, object message, Type messageType, CancellationToken cancellationToken = default) { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, messageType, cancellationToken)); }
public async Task Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { var serviceProvider = context.GetPayload <IServiceProvider>(); var currentUserService = serviceProvider.GetService <ICurrentUserService>(); var identityService = serviceProvider.GetService <IIdentityService>(); var logger = serviceProvider.GetService <ILogger <LoggingFilter <TMessage> > >(); var requestName = typeof(TMessage).Name; var userId = currentUserService.UserId ?? string.Empty; string userName = string.Empty; if (!string.IsNullOrEmpty(userId)) { userName = await identityService.GetUserNameAsync(userId); } var request = context.Message; // 이게 메시지. logger.LogWarning("**MassTransit Filter** CleanArchitecture Request: {Name} {@UserId} {@UserName} {@Request}", requestName, userId, userName, request); // masstransit의 filter는 반드시 next.Send() 를 호출해야 흐름이 안끊긴다 // (반대로, 흐름을 끊으려면, 이걸 호출안하면 된다) await next.Send(context); }
/// <summary> /// Sends an object as a message, using the message type specified. If the object cannot be cast /// to the specified message type, an exception will be thrown. /// </summary> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message object</param> /// <param name="messageType">The type of the message (use message.GetType() if desired)</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> SchedulePublish(this ConsumeContext context, DateTime scheduledTime, object message, Type messageType, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.SchedulePublish(scheduledTime, message, messageType, pipe, cancellationToken)); }
public Task Send(ConsumeContext <TData> context) { using (RetryPolicyContext <ConsumeContext <TData> > policyContext = _retryPolicy.CreatePolicyContext(context)) { var exception = new SagaException("An existing saga instance was not found", typeof(TInstance), typeof(TData), context.CorrelationId ?? Guid .Empty); if (!policyContext.CanRetry(exception, out RetryContext <ConsumeContext <TData> > retryContext)) { return(_finalPipe.Send(context)); } int previousDeliveryCount = context.GetRedeliveryCount(); for (int retryIndex = 0; retryIndex < previousDeliveryCount; retryIndex++) { if (!retryContext.CanRetry(exception, out retryContext)) { return(_finalPipe.Send(context)); } } var schedulerContext = context.GetPayload <MessageSchedulerContext>(); MessageRedeliveryContext redeliveryContext = new ScheduleMessageRedeliveryContext <TData>(context, schedulerContext); var delay = retryContext.Delay ?? TimeSpan.Zero; return(redeliveryContext.ScheduleRedelivery(delay)); } }
public async Task Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { var provider = context.GetPayload <IServiceProvider>(); var unitOfWork = provider.GetRequiredService <UnitOfWork>(); await next.Send(context); }
/// <summary> /// Sends an object as a message, using the type of the message instance. /// </summary> /// <param name="context">The consume context</param> /// <param name="message">The message object</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> ScheduleSend(this ConsumeContext context, DateTime scheduledTime, object message, CancellationToken cancellationToken = default(CancellationToken)) { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(context.ReceiveContext.InputAddress, scheduledTime, message, cancellationToken)); }
public async Task Send(ConsumeContext <T> context, IPipe <ConsumeContext <T> > next) { var serviceProvider = context.GetPayload <IServiceProvider>(); var logger = serviceProvider.GetService <ILogger <CorrelationConsumeContextFilter <T> > >(); logger.LogDebug("Start CorrelationConsumeContextFilter"); var correlationId = context.Headers.Get <string>(Consts.CorrelationIdHeaderKey); if (string.IsNullOrEmpty(correlationId)) { correlationId = NewId.NextGuid().ToString(); logger.LogWarning("CorrelationConsumeContextFilter received a message missing a required Correlation-ID in its header. Type={type}, Set new Id={Correlation-ID}", TypeMetadataCache <T> .ShortName, correlationId); } var correlationContextAccessor = serviceProvider.GetService <ICorrelationContextAccessor>(); correlationContextAccessor.CorrelationContext = new CorrelationContext(correlationId, Consts.CorrelationIdHeaderKey); using (logger.BeginScope(new Dictionary <string, object> { [Consts.CorrelationIdHeaderKey] = correlationId })) { logger.LogInformation("CorrelationConsumeContextFilter found correlationId in header and set in logger and correlationContextAccessor."); await next.Send(context); }; }
public async Task Consume(ConsumeContext <PingMessage> context) { var transaction = context.GetPayload <IUnitOfWork>(); Console.WriteLine("Using transaction"); await context.RespondAsync(new PongMessage(context.Message.CorrelationId)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this ConsumeContext context, DateTime scheduledTime, T message, CancellationToken cancellationToken = default) where T : class { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.SchedulePublish(scheduledTime, message, cancellationToken)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="context">The consume context</param> /// <param name="message">The message</param> /// <param name="destinationAddress">The destination address where the schedule message should be sent</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > ScheduleSend <T>(this ConsumeContext context, Uri destinationAddress, DateTime scheduledTime, T message, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) where T : class { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, pipe, cancellationToken)); }
Task IFilter <ConsumeContext <TMessage> > .Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next) { var schedulerContext = context.GetPayload <MessageSchedulerContext>(); context.GetOrAddPayload <MessageRedeliveryContext>(() => new ScheduleMessageRedeliveryContext <TMessage>(context, schedulerContext)); return(next.Send(context)); }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="context">The consume context</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > ScheduleSend <T>(this ConsumeContext context, DateTime scheduledTime, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend <T>(context.ReceiveContext.InputAddress, scheduledTime, values, pipe, cancellationToken)); }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="context">The consume context</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="destinationAddress">The destination address where the schedule message should be sent</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > ScheduleSend <T>(this ConsumeContext context, Uri destinationAddress, DateTime scheduledTime, object values, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend <T>(destinationAddress, scheduledTime, values, cancellationToken)); }
public Task Send(ConsumeContext <SubmitOrder> context, IPipe <ConsumeContext <SubmitOrder> > next) { var provider = context.GetPayload <IServiceProvider>(); Console.WriteLine("Filter ran"); return(next.Send(context)); }
public Task Send(ConsumeContext <CreateWorkItemEvent> context, IPipe <ConsumeContext <CreateWorkItemEvent> > next) { var provider = context.GetPayload <IServiceProvider>(); Trace.WriteLine("Filter ran"); return(next.Send(context)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this ConsumeContext context, DateTime scheduledTime, T message, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetDestinationAddress(context, typeof(T)); var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, cancellationToken)); }
public async Task Consume(ConsumeContext <SendMail> context) { var smtpContext = context.GetPayload <SmtpContext>(); var message = CreateMimeMessage(context); await smtpContext.Send(message, context.CancellationToken).ConfigureAwait(false); await context.Publish <MailSent>(new { context.Message.CorrelationId }).ConfigureAwait(false); }
IMessageScheduler CreateMessageScheduler() { if (_context.TryGetPayload <IMessageScheduler>(out var scheduler)) { return(scheduler); } var provider = new ActiveMqScheduleMessageProvider(_context); return(new MessageScheduler(provider, _context.GetPayload <IBusTopology>())); }
public Task Consume(ConsumeContext <OrderBilled> context) { var logger = context.GetPayload <IServiceProvider>().GetService <ILogger <ShippingSaga> >(); OrderBilledDate = context.Message.BillingDate; Thread.Sleep(rnd.Next(0, 2000)); logger.LogInformation($"Received OrderBilled, OrderId = {context.Message.OrderId}, billing date = {context.Message.BillingDate}"); ProcessOrder(logger); return(Task.CompletedTask); }
public Task Consume(ConsumeContext <Message> context) { var transactionContext = context.GetPayload <TransactionContext>(); var isolationLevel = transactionContext.Transaction.IsolationLevel; using (var ts = new TransactionScope(transactionContext.Transaction)) { throw new IntentionalTestException("Then, you, shall, die!"); } }
/// <summary> /// Sends an object as a message, using the message type specified. If the object cannot be cast /// to the specified message type, an exception will be thrown. /// </summary> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message object</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> SchedulePublish(this ConsumeContext context, DateTime scheduledTime, object message, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.SchedulePublish(scheduledTime, message, pipe, cancellationToken)); }
IMessageScheduler CreateMessageScheduler() { if (_context.TryGetPayload <IMessageScheduler>(out var scheduler)) { return(scheduler); } var hostTopology = _context.GetPayload <IRabbitMqHostTopology>(); var provider = new DelayedExchangeScheduleMessageProvider(_context, hostTopology); return(new MessageScheduler(provider, hostTopology)); }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this ConsumeContext context, DateTime scheduledTime, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) where T : class { if (values == null) { throw new ArgumentNullException(nameof(values)); } var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.SchedulePublish <T>(scheduledTime, values, pipe, cancellationToken)); }
/// <summary> /// Sends an object as a message, using the message type specified. If the object cannot be cast /// to the specified message type, an exception will be thrown. /// </summary> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message object</param> /// <param name="messageType">The type of the message (use message.GetType() if desired)</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> SchedulePublish(this ConsumeContext context, DateTime scheduledTime, object message, Type messageType, CancellationToken cancellationToken = default(CancellationToken)) { if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } var destinationAddress = GetDestinationAddress(context, messageType); var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, messageType, cancellationToken)); }
public async Task Should_include_container_scope() { await InputQueueSendEndpoint.Send(new EasyMessage { CorrelationId = NewId.NextGuid() }); ConsumerConsumeContext <EasyConsumer> consumerContext = await _consumerCompletion.Task; var scope = consumerContext.GetPayload <TScope>(); ConsumerConsumeContext <EasyConsumer, EasyMessage> consumerMessageContext = await _consumerMessageCompletion.Task; Assert.AreEqual(scope, consumerMessageContext.GetPayload <TScope>()); ConsumeContext <EasyMessage> messageContext = await MessageCompletion.Task; Assert.AreEqual(scope, messageContext.GetPayload <TScope>()); }
/// <summary> /// Cancel a scheduled message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="context">The message scheduler</param> /// <param name="message">The </param> /// <returns></returns> public static Task CancelScheduledSend <T>(this ConsumeContext context, ScheduledMessage <T> message) where T : class { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.CancelScheduledSend(message.Destination, message.TokenId)); }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="context">The consume context</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this ConsumeContext context, DateTime scheduledTime, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { if (values == null) { throw new ArgumentNullException(nameof(values)); } var message = TypeMetadataCache <T> .InitializeFromObject(values); var destinationAddress = GetDestinationAddress <T>(context); var scheduler = context.GetPayload <MessageSchedulerContext>(); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, pipe, cancellationToken)); }
/// <summary> /// Initializes a new instance. /// </summary> /// <param name="bus"></param> public ConsumeContextRequestClientProxy(ConsumeContext context) { this.impl = context.CreateRequestClient <TRequest>(context.GetPayload <IBus>()); }