Ejemplo n.º 1
0
        /// <summary>
        /// Send the given object to the specified destination, converting the object
        /// to a MSMQ message with a configured <see cref="IMessageConverter"/> and resolving the
        /// destination name to a <see cref="MessageQueue"/> with an <see cref="IMessageQueueFactory"/>
        /// The <see cref="MessagePostProcessorDelegate"/> callback allows for modification of the message after conversion.
        /// </summary>
        /// <param name="messageQueueObjectName">the name of the destination queue
        /// to send this message to (to be resolved to an actual MessageQueue
        /// by a IMessageQueueFactory)</param>
        /// <param name="obj">the object to convert to a message</param>
        /// <param name="messagePostProcessorDelegate">the callback to modify the message</param>
        /// <exception cref="MessagingException">if thrown by MSMQ API methods</exception>
        public void ConvertAndSend(string messageQueueObjectName, object obj,
                                   MessagePostProcessorDelegate messagePostProcessorDelegate)
        {
            Message msg       = MessageConverter.ToMessage(obj);
            Message msgToSend = messagePostProcessorDelegate(msg);

            Send(MessageQueueFactory.CreateMessageQueue(messageQueueObjectName), msgToSend);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Ensure that the MessageQueueObject name is set and creates a
 /// <see cref="DefaultMessageQueueFactory"/> if no <see cref="IMessageQueueFactory"/>
 /// is specified.
 /// </summary>
 /// <remarks>Will attempt to create an instance of the DefaultMessageQueue to detect early
 /// any configuraiton errors.</remarks>
 /// <exception cref="System.Exception">
 /// In the event of misconfiguration (such as the failure to set a
 /// required property) or if initialization fails.
 /// </exception>
 public virtual void AfterPropertiesSet()
 {
     if (MessageQueueObjectName == null)
     {
         throw new ArgumentException("The DefaultMessageQueueObjectName property has not been set.");
     }
     if (messageQueueFactory == null)
     {
         DefaultMessageQueueFactory mqf = new DefaultMessageQueueFactory();
         mqf.ApplicationContext = applicationContext;
         messageQueueFactory    = mqf;
     }
     //Create an instance so we can 'fail-fast' if there isn't an DefaultMessageQueue unde
     MessageQueue mq = MessageQueueFactory.CreateMessageQueue(messageQueueObjectName);
 }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .AddInMemoryCollection(new Dictionary <string, string>
            {
                { "QueueHostName", "localhost" },
                { "LogLevel", LogEventLevel.Information.ToString() }
            })
                         .AddEnvironmentVariables()
                         .Build();

            var logLevel = LogEventLevel.Warning;

            Enum.TryParse(config["LogLevel"], out logLevel);

            var logLevelSwitch = new Serilog.Core.LoggingLevelSwitch(logLevel);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.ControlledBy(logLevelSwitch)
                         .WriteTo.LiterateConsole()
                         .CreateLogger();

            var traderId = Guid.NewGuid().ToString("n").Substring(0, 8);

            Log.Information("Starting Trade Bot {traderId}...", traderId);

            var queueHost = config["QueueHost"];

            Log.Verbose("Connecting to message host {queueHost}...", queueHost);

            using (var connection = MessageQueueFactory.Connect(queueHost))
                using (var channel = connection.CreateModel())
                {
                    var queue  = MessageQueueFactory.CreateMessageQueue(channel, config["QueueName"]);
                    var trader = new TradeGenerator(traderId);

                    while (true)
                    {
                        var trade = trader.GenerateTrade();

                        queue.Publish(trade.Type.ToString().ToLower(), trade);

                        Thread.Sleep(1000);
                    }
                }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Sends the specified message to the message queue using the
 /// transactional settings as dicted by MessageQueue's Transactional property and
 /// the current Spring managed ambient transaction.
 /// </summary>
 /// <param name="messageQueueObjectName">Name of the message queue object.</param>
 /// <param name="message">The message.</param>
 public void Send(string messageQueueObjectName, Message message)
 {
     Send(MessageQueueFactory.CreateMessageQueue(messageQueueObjectName), message);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Receives  a message on the specified queue using the transactional settings as dicted by MessageQueue's Transactional property and
 /// the current Spring managed ambient transaction.
 /// </summary>
 /// <param name="messageQueueObjectName">Name of the message queue object.</param>
 /// <returns></returns>
 public Message Receive(string messageQueueObjectName)
 {
     return(MessageQueueFactory.CreateMessageQueue(messageQueueObjectName).Receive(ReceiveTimeout));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Send the given object to the specified destination, converting the object
        /// to a MSMQ message with a configured <see cref="IMessageConverter"/> and resolving the
        /// destination name to a <see cref="MessageQueue"/> using a <see cref="IMessageQueueFactory"/>
        /// </summary>
        /// <param name="messageQueueObjectName">the name of the destination queue
        /// to send this message to (to be resolved to an actual MessageQueue
        /// by a IMessageQueueFactory)</param>
        /// <param name="obj">the object to convert to a message</param>
        /// <throws>NMSException if there is any problem</throws>
        public void ConvertAndSend(string messageQueueObjectName, object obj)
        {
            Message msg = MessageConverter.ToMessage(obj);

            Send(MessageQueueFactory.CreateMessageQueue(messageQueueObjectName), msg);
        }
 /// <summary>
 /// Retrieves a MessageQueue instance given the MessageQueueObjectName
 /// </summary>
 protected override void DoInitialize()
 {
     messageQueue = MessageQueueFactory.CreateMessageQueue(MessageQueueObjectName);
     //TODO would initialize resources for a seperate thread pool here.
 }
 private MessageQueue GetResponseQueue()
 {
     return(MessageQueueFactory.CreateMessageQueue(defaultResponseQueueObjectName));
 }