示例#1
0
        /// <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));
        }
示例#2
0
        /// <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));
        }
示例#3
0
        /// <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));
        }
示例#4
0
        /// <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 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)));
        }