/// <summary> /// Sends an object as a message, using the type of the message instance. /// </summary> /// <param name="endpoint">The message scheduler endpoint</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="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage> ScheduleSend(this IPublishEndpoint endpoint, Uri destinationAddress, DateTime scheduledTime, object message, CancellationToken cancellationToken = default) { IMessageScheduler scheduler = new MessageScheduler(new PublishScheduleMessageProvider(endpoint)); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, 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="endpoint">The message scheduler endpoint</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 ISendEndpoint endpoint, Uri destinationAddress, DateTime scheduledTime, object message, Type messageType, CancellationToken cancellationToken = default) { IMessageScheduler scheduler = new MessageScheduler(new EndpointScheduleMessageProvider(() => Task.FromResult(endpoint))); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, messageType, cancellationToken)); }
/// <summary> /// Cancel a scheduled message using the tokenId that was returned when the message was scheduled. /// </summary> /// <param name="endpoint">The endpoint of the scheduling service</param> /// <param name="tokenId">The tokenId of the scheduled message</param> public static Task CancelScheduledSend(this ISendEndpoint endpoint, Guid tokenId) { IMessageScheduler scheduler = new MessageScheduler(new EndpointScheduleMessageProvider(() => Task.FromResult(endpoint))); return(scheduler.CancelScheduledSend(tokenId)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="endpoint">The message scheduler endpoint</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 ISendEndpoint endpoint, Uri destinationAddress, DateTime scheduledTime, T message, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) where T : class { IMessageScheduler scheduler = new MessageScheduler(new EndpointScheduleMessageProvider(() => Task.FromResult(endpoint))); return(scheduler.ScheduleSend(destinationAddress, scheduledTime, message, 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="endpoint">The message scheduler endpoint</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="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 IPublishEndpoint endpoint, Uri destinationAddress, DateTime scheduledTime, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default) where T : class { IMessageScheduler scheduler = new MessageScheduler(new PublishScheduleMessageProvider(endpoint)); return(scheduler.ScheduleSend <T>(destinationAddress, scheduledTime, values, pipe, cancellationToken)); }
public HomeController(ILogger <HomeController> logger, DataService ds, MessageScheduler ms, Caching data) { _logger = logger; _ds = ds; _ms = ms; _data = data; }
public void When_Scheduling_A_Command_It_Is_Pushed_To_The_Store() { var schedulerStore = new MockSchedulerStore(); var commandScheduler = new MessageScheduler(schedulerStore); commandScheduler.ScheduleMessage(new TestCommand() { Test = "TestText"}, new DateTime(2012, 06, 24, 13, 37, 42)); Assert.AreEqual(1, schedulerStore.PushedMessages.Count); Assert.AreEqual(new DateTime(2012, 06, 24, 13, 37, 42), schedulerStore.PushedMessages[0].Item2); }
Task IFilter <ConsumeContext> .Send(ConsumeContext context, IPipe <ConsumeContext> next) { context.GetOrAddPayload <MessageSchedulerContext>(() => { var scheduler = new MessageScheduler(new ServiceBusScheduleMessageProvider(context)); return(new ConsumeMessageSchedulerContext(scheduler, context.ReceiveContext.InputAddress)); }); return(next.Send(context)); }
Task IFilter<ConsumeContext>.Send(ConsumeContext context, IPipe<ConsumeContext> next) { MessageSchedulerContext PayloadFactory() { var scheduler = new MessageScheduler(new DelayedMessageScheduleMessageProvider(context)); return new ConsumeMessageSchedulerContext(scheduler, context.ReceiveContext.InputAddress); } context.GetOrAddPayload(PayloadFactory); return next.Send(context); }
Task IFilter <ConsumeContext> .Send(ConsumeContext context, IPipe <ConsumeContext> next) { MessageSchedulerContext PayloadFactory() { var scheduler = new MessageScheduler(new EndpointScheduleMessageProvider(() => context.GetSendEndpoint(_schedulerAddress))); return(new ConsumeMessageSchedulerContext(scheduler, context.ReceiveContext.InputAddress)); } context.GetOrAddPayload(PayloadFactory); return(next.Send(context)); }
/// <summary> /// Defers the message for redelivery using a delayed exchange. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <param name="callback"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null) where T : class { if (!context.TryGetPayload(out IMessageScheduler scheduler)) { var provider = new ActiveMqScheduleMessageProvider(context); scheduler = new MessageScheduler(provider); } MessageRedeliveryContext redeliveryContext = new ActiveMqMessageRedeliveryContext <T>(context, scheduler); return(redeliveryContext.ScheduleRedelivery(delay, callback)); }
Task IFilter <ConsumeContext> .Send(ConsumeContext context, IPipe <ConsumeContext> next) { MessageSchedulerContext PayloadFactory() { var modelContext = context.ReceiveContext.GetPayload <ModelContext>(); var scheduler = new MessageScheduler(new DelayedExchangeScheduleMessageProvider(context, modelContext.ConnectionContext.Topology)); return(new ConsumeMessageSchedulerContext(scheduler, context.ReceiveContext.InputAddress)); } context.GetOrAddPayload(PayloadFactory); return(next.Send(context)); }
public async Task Should_get_both_messages() { var scheduler = new MessageScheduler(new DelayedScheduleMessageProvider(Bus), Bus.Topology); await scheduler.ScheduleSend(InputQueueAddress, TimeSpan.FromSeconds(3), new FirstMessage()); await _first; var timer = Stopwatch.StartNew(); await _second; timer.Stop(); Assert.That(timer.Elapsed, Is.LessThan(TimeSpan.FromSeconds(1))); }
/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <param name="callback"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null) where T : class { if (!context.TryGetPayload(out IMessageScheduler scheduler)) { if (!context.TryGetPayload(out ModelContext modelContext)) { throw new ArgumentException("A valid message scheduler was not found, and no ModelContext was available", nameof(context)); } var provider = new DelayedExchangeScheduleMessageProvider(context, modelContext.ConnectionContext.Topology); scheduler = new MessageScheduler(provider); } MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context, scheduler); return(redeliveryContext.ScheduleRedelivery(delay, callback)); }
/// <summary> /// Initializes the ModuleClient and sets up the callback to receive /// messages containing temperature information /// </summary> static async Task Init() { MqttTransportSettings mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only); ITransportSettings[] settings = { mqttSetting }; // Open a connection to the Edge runtime ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings); await ioTHubModuleClient.OpenAsync(); Console.WriteLine("IoT Hub module client initialized."); // Register callback to be called when a message is received by the module await ioTHubModuleClient.SetInputMessageHandlerAsync(Constants.Inputs.Schedule, PipeMessage, ioTHubModuleClient, cts.Token); module = new Scheduler.Module(); scheduleTask = MessageScheduler.Create(module, ioTHubModuleClient, cts.Token); }
/// <summary> /// Cancel a scheduled message using the tokenId that was returned when the message was scheduled. /// </summary> /// <param name="endpoint">The endpoint of the scheduling service</param> /// <param name="tokenId">The tokenId of the scheduled message</param> public static Task CancelScheduledSend(this IPublishEndpoint endpoint, Guid tokenId) { IMessageScheduler scheduler = new MessageScheduler(new PublishScheduleMessageProvider(endpoint)); return(scheduler.CancelScheduledSend(tokenId)); }