private static void ScheduleMessagesWithQuartzInMemory() { string rabbitMqAddress = "rabbitmq://localhost:5672/accounting"; string rabbitMqQueue = "mycompany.queues.news.scheduled"; Uri rabbitMqRootUri = new Uri(rabbitMqAddress); IBusControl rabbitBusControl = Bus.Factory.CreateUsingRabbitMq(rabbit => { rabbit.Host(rabbitMqRootUri, settings => { settings.Password("accountant"); settings.Username("accountant"); }); rabbit.UseInMemoryScheduler(); }); Uri sendUri = new Uri(string.Concat(rabbitMqAddress, "/", rabbitMqQueue)); Task <ISendEndpoint> sendEndpointTask = rabbitBusControl.GetSendEndpoint(sendUri); ISendEndpoint sendEndpoint = sendEndpointTask.Result; Task <ScheduledMessage <IWorldNews> > scheduledMessageTask = sendEndpoint.ScheduleSend <IWorldNews> (new Uri("rabbitmq://localhost:5672/quartz"), TimeSpan.FromSeconds(30), new { Message = "The world is going down." }); ScheduledMessage <IWorldNews> scheduledMessage = scheduledMessageTask.Result; Console.ReadKey(); }
/// <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="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</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 IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, object message, Type messageType, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) { var destinationAddress = GetPublishAddress(bus, messageType); return(schedulerEndpoint.ScheduleSend(destinationAddress, scheduledTime, message, messageType, pipe, cancellationToken)); }
protected async Task SendRequest(BehaviorContext <TInstance> context, ConsumeContext consumeContext, TRequest requestMessage) { var pipe = new SendRequestPipe(consumeContext.ReceiveContext.InputAddress); ISendEndpoint endpoint = await consumeContext.GetSendEndpoint(_request.Settings.ServiceAddress).ConfigureAwait(false); await endpoint.Send(requestMessage, pipe).ConfigureAwait(false); _request.SetRequestId(context.Instance, pipe.RequestId); if (_request.Settings.Timeout > TimeSpan.Zero) { DateTime now = DateTime.UtcNow; DateTime expirationTime = now + _request.Settings.Timeout; RequestTimeoutExpired message = new TimeoutExpired(now, expirationTime, context.Instance.CorrelationId, pipe.RequestId); MessageSchedulerContext schedulerContext; if (_request.Settings.SchedulingServiceAddress != null) { ISendEndpoint scheduleEndpoint = await consumeContext.GetSendEndpoint(_request.Settings.SchedulingServiceAddress).ConfigureAwait(false); await scheduleEndpoint.ScheduleSend(consumeContext.ReceiveContext.InputAddress, expirationTime, message).ConfigureAwait(false); } else if (consumeContext.TryGetPayload(out schedulerContext)) { await schedulerContext.ScheduleSend(expirationTime, message).ConfigureAwait(false); } else { throw new ConfigurationException("A request timeout was specified but no message scheduler was specified or available"); } } }
/// <summary> /// Sends a ScheduleMessage command to the endpoint, using the specified arguments /// </summary> /// <typeparam name="T">The scheduled message type</typeparam> /// <param name="endpoint">The endpoint of the message scheduling service</param> /// <param name="host"></param> /// <param name="scheduledTime">The time when the message should be sent to the endpoint</param> /// <param name="message">The message to send</param> /// <returns>A handled to the scheduled message</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this ISendEndpoint endpoint, IRabbitMqHost host, DateTime scheduledTime, T message) where T : class { var destinationAddress = GetDestinationAddress(host, typeof(T)); return(endpoint.ScheduleSend(destinationAddress, scheduledTime, message)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</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="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 IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, T message, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetPublishAddress <T>(bus); return(schedulerEndpoint.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="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</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="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 IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, object values, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetPublishAddress <T>(bus); return(schedulerEndpoint.ScheduleSend <T>(destinationAddress, scheduledTime, values, 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="bus">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 IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetDestinationAddress(bus, typeof(T)); return(schedulerEndpoint.ScheduleSend <T>(destinationAddress, scheduledTime, values, pipe, cancellationToken)); }
public async Task <ScheduledMessage <T> > ScheduleSend <T>(T message, Uri destinationAddress, DateTime deliveryTime, IPipe <SendContext> sendPipe) where T : class { ISendEndpoint endpoint = await _schedulerEndpoint.Value.ConfigureAwait(false); ScheduledMessage <T> scheduledMessage = await endpoint.ScheduleSend(destinationAddress, deliveryTime, message, sendPipe) .ConfigureAwait(false); return(scheduledMessage); }
/// <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="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</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 IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, object message, Type messageType, CancellationToken cancellationToken = default(CancellationToken)) { if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } var destinationAddress = GetPublishAddress(bus, messageType); return(schedulerEndpoint.ScheduleSend(destinationAddress, scheduledTime, message, messageType, cancellationToken)); }