Beispiel #1
0
        async Task <ScheduledMessage <T> > ScheduleSend <T>(Uri destinationAddress, DateTime scheduledTime, T message, CancellationToken cancellationToken)
            where T : class
        {
            Guid tokenId = ScheduleTokenIdCache <T> .GetTokenId(message);

            ScheduleMessage <T> command = new ScheduleMessageCommand <T>(scheduledTime, destinationAddress, message, tokenId);

            await _publishEndpoint.Publish(command, cancellationToken).ConfigureAwait(false);

            return(new ScheduledMessageHandle <T>(command.CorrelationId, command.ScheduledTime, command.Destination, command.Payload));
        }
        async Task <ScheduledMessage <T> > ScheduleSend <T>(Uri destinationAddress, DateTime scheduledTime, T message, IPipe <SendContext <ScheduleMessage <T> > > pipe,
                                                            CancellationToken cancellationToken)
            where T : class
        {
            Guid tokenId = ScheduleTokenIdCache <T> .GetTokenId(message);

            ScheduleMessage <T> command = new ScheduleMessageCommand <T>(scheduledTime, destinationAddress, message, tokenId);

            var endpoint = await _schedulerEndpoint.Value.ConfigureAwait(false);

            await endpoint.Send(command, pipe, cancellationToken).ConfigureAwait(false);

            return(new ScheduledMessageHandle <T>(command.CorrelationId, command.ScheduledTime, command.Destination, command.Payload));
        }
        public override Task Send(SendContext <T> context)
        {
            ScheduledMessageId = ScheduleTokenIdCache <T> .GetTokenId(context.Message, context.MessageId);

            var delay = Math.Max(0, (long)(_scheduledTime.Kind == DateTimeKind.Local
                ? _scheduledTime - DateTime.Now
                : _scheduledTime - DateTime.UtcNow).TotalMilliseconds);

            if (delay > 0)
            {
                context.Headers.Set("AMQ_SCHEDULED_DELAY", delay);
            }

            return(base.Send(context));
        }
Beispiel #4
0
        public override Task Send(SendContext <T> context)
        {
            ScheduledMessageId = ScheduleTokenIdCache <T> .GetTokenId(context.Message, context.MessageId);

            var sqsSendContext = context.GetPayload <AmazonSqsSendContext>();

            var delay = Math.Max(0, (_scheduledTime.Kind == DateTimeKind.Local
                ? _scheduledTime - DateTime.Now
                : _scheduledTime - DateTime.UtcNow).TotalSeconds);

            if (delay > 0)
            {
                sqsSendContext.DelaySeconds = (int)delay;
            }

            return(base.Send(context));
        }
        public override Task Send(SendContext <T> context)
        {
            ScheduledMessageId = ScheduleTokenIdCache <T> .GetTokenId(context.Message, context.MessageId);

            var rabbitSendContext = context.GetPayload <RabbitMqSendContext>();

            var delay = Math.Max(0, (_scheduledTime.Kind == DateTimeKind.Local
                ? _scheduledTime - DateTime.Now
                : _scheduledTime - DateTime.UtcNow).TotalMilliseconds);

            if (delay > 0)
            {
                rabbitSendContext.SetTransportHeader("x-delay", (long)delay);
            }

            return(base.Send(context));
        }
        public async Task <ScheduledMessage <T> > ScheduleSend <T>(Uri destinationAddress, DateTime scheduledTime, Task <T> message, IPipe <SendContext <T> > pipe,
                                                                   CancellationToken cancellationToken)
            where T : class
        {
            var payload = await message.ConfigureAwait(false);

            var scheduleMessagePipe = new ServiceBusScheduleSendPipe <T>(pipe, scheduledTime);

            var tokenId = ScheduleTokenIdCache <T> .GetTokenId(payload);

            scheduleMessagePipe.ScheduledMessageId = tokenId;

            var endpoint = await _sendEndpointProvider.GetSendEndpoint(destinationAddress).ConfigureAwait(false);

            await endpoint.Send(payload, scheduleMessagePipe, cancellationToken).ConfigureAwait(false);

            return(new ScheduledMessageHandle <T>(scheduleMessagePipe.ScheduledMessageId ?? NewId.NextGuid(), scheduledTime, destinationAddress, payload));
        }
Beispiel #7
0
        async Task <ScheduledMessage <T> > IScheduleMessageProvider.ScheduleSend <T>(Uri destinationAddress, DateTime scheduledTime, Task <T> message,
                                                                                     IPipe <SendContext <T> > pipe, CancellationToken cancellationToken)
        {
            var scheduleMessagePipe = new ScheduleMessageContextPipe <T>(pipe);

            var payload = await message.ConfigureAwait(false);

            var tokenId = ScheduleTokenIdCache <T> .GetTokenId(payload);

            scheduleMessagePipe.ScheduledMessageId = tokenId;

            ScheduleMessage <T> command = new ScheduleMessageCommand <T>(scheduledTime, destinationAddress, payload, tokenId);

            await ScheduleSend(command, scheduleMessagePipe, cancellationToken).ConfigureAwait(false);

            return(new ScheduledMessageHandle <T>(scheduleMessagePipe.ScheduledMessageId ?? command.CorrelationId, command.ScheduledTime,
                                                  command.Destination,
                                                  command.Payload));
        }