Beispiel #1
0
 /// <summary>
 /// Creates the fake advanced API, using the given implementation(s). All arguments are optional
 /// </summary>
 public FakeAdvancedApi(IWorkersApi workers = null, ITopicsApi topics = null, IRoutingApi routing = null, ITransportMessageApi transportMessage = null, IDataBus dataBus = null)
 {
     _workers = workers;
     _topics = topics;
     _routing = routing;
     _transportMessage = transportMessage;
     _dataBus = dataBus;
 }
Beispiel #2
0
 /// <summary>
 /// Creates the fake advanced API, using the given implementation(s). All arguments are optional
 /// </summary>
 public FakeAdvancedApi(IWorkersApi workers = null, ITopicsApi topics = null, IRoutingApi routing = null, ITransportMessageApi transportMessage = null, IDataBus dataBus = null)
 {
     _workers          = workers;
     _topics           = topics;
     _routing          = routing;
     _transportMessage = transportMessage;
     _dataBus          = dataBus;
 }
Beispiel #3
0
        /// <summary>
        /// Manually dead-letters the message currently being handled. Optionally passes the given <paramref name="errorDetails"/> along as the <see cref="Headers.ErrorDetails"/> header.
        /// </summary>
        public static async Task Deadletter(this ITransportMessageApi transportMessageApi, string errorDetails = null, bool throwIfAlreadyDeadlettered = true)
        {
            if (transportMessageApi == null)
            {
                throw new ArgumentNullException(nameof(transportMessageApi));
            }

            var context     = MessageContext.Current ?? throw new InvalidOperationException($"Attempted to dead-letter the current message using error details '{errorDetails}', but no message context could be found! This is probably a sign that this method was called OUTSIDE of a Rebus handler, or on a separate, disconnected thread somehow. Please only call this method inside Rebus handlers.");
            var stepContext = context.IncomingStepContext;

            if (throwIfAlreadyDeadlettered)
            {
                var existing = stepContext.Load <ManualDeadletterCommand>();

                if (existing != null)
                {
                    throw new InvalidOperationException($"Cannot dead-letter the current message with error details '{errorDetails}', because the message was already marked as dead-lettered with these details: '{existing.ErrorDetails}'. If you want, you can force the dead-lettering to be overwritten, by setting the {nameof(throwIfAlreadyDeadlettered)} flag when deadlettering the message");
                }
            }

            stepContext.Save(new ManualDeadletterCommand(errorDetails));
        }
Beispiel #4
0
 public TestMessageHandler(IMessageContext messageContext, ITransportMessageApi transportMessageApi)
 {
     _messageContext      = messageContext;
     _transportMessageApi = transportMessageApi;
 }