public IEnumerable <UserModel> Get() { mqManager.Send("Hello world"); return(userService.Get() .Select(x => x.Map <User, UserModel>()) .ToList()); }
private void SendMessage <T>(T message, IMessageQueueTransaction messageQueueTransaction) { var jsonSerializerSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var queueMessage = new QueueMessage { MessageBody = message.SerializeToJson(jsonSerializerSettings), MessageType = typeof(T) }; using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(queueMessage.SerializeToJson(jsonSerializerSettings)))) { var buffer = new byte[MaxMsmqMessageSize]; var correlationId = ""; var messageSize = memoryStream.Length; var numberOfChunks = Convert.ToInt32(Math.Ceiling((double)messageSize / buffer.Length)); int bytes; var chunk = 0; Logger.Debug("Message send {QueueName} {Type} {%Message}", Name, queueMessage.MessageType.FullName, queueMessage.MessageBody); if (!Transactional && numberOfChunks > 1) { throw new MessageSizeException(memoryStream.Length, buffer.Length, Transactional); } while ((bytes = memoryStream.Read(buffer, 0, buffer.Length)) > 0) { var mqMessage = new Message { AppSpecific = numberOfChunks, CorrelationId = correlationId }; mqMessage.BodyStream.Write(buffer, 0, bytes); Logger.Debug("Sending message chunk ({Chunk}/{NumberOfChunks}) on {QueueName} {CorrelationId}", ++chunk, numberOfChunks, Name, correlationId); MessageQueueManager.Send(MessageQueue, mqMessage, messageQueueTransaction?.Transaction); correlationId = mqMessage.Id; } } }
private string SendMessage(System.Messaging.MessageQueue queue, object body, string correlationId = null) { var messageQueueTransaction = new System.Messaging.MessageQueueTransaction(); messageQueueTransaction.Begin(); var message = new Message { Body = body }; if (correlationId != null) { message.CorrelationId = correlationId; } _messageQueueManager.Send(queue, message, messageQueueTransaction); messageQueueTransaction.Commit(); return(message.Id); }