Beispiel #1
0
        public TransportMessage Send(object message, Action <TransportMessageConfigurator> configure)
        {
            Guard.AgainstNull(message, nameof(message));

            var result = _transportMessageFactory.Create(message, configure, _transportMessageReceived);

            Dispatch(result);

            return(result);
        }
Beispiel #2
0
        public IActionResult Post([FromBody] SendMessageModel model)
        {
            Guard.AgainstNull(model, nameof(model));

            IQueue queue = null;

            try
            {
                queue = _queueManager.CreateQueue(model.DestinationQueueUri);

                var transportMessage = _transportMessageFactory.Create(new object(), c => c.WithRecipient(queue));

                transportMessage.AssemblyQualifiedName = model.MessageType;
                transportMessage.MessageType           = model.MessageType;
                transportMessage.Message = Encoding.UTF8.GetBytes(model.Message);

                using (var stream = _serializer.Serialize(transportMessage))
                {
                    queue.Enqueue(transportMessage, stream);
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            finally
            {
                queue?.AttemptDispose();
            }

            return(Ok());
        }