public void Invoke(ReceivePhysicalMessageContext context, Action next)
        {
            var transportMessage = context.PhysicalMessage;

            //change reply to to the other half of the bridge
            transportMessage.ReplyToAddress = Address.Parse("MsmqAsbBridge@" + Environment.MachineName);

            var sender = new MsmqMessageSender {
                Settings = new MsmqSettings(), UnitOfWork = new MsmqUnitOfWork()
            };

            sender.Send(transportMessage, Address.Parse("MsmqEndpoint@" + Environment.MachineName));
        }
コード例 #2
0
        public void Init()
        {
            NServiceBus.Configure.With().Log4Net().DefaultBuilder().UnicastBus();

            string errorQueue = ConfigurationManager.AppSettings["ErrorQueue"];
            string audit      = ConfigurationManager.AppSettings["ForwardReceivedMessageTo"];
            string listenUrl  = ConfigurationManager.AppSettings["ListenUrl"];
            string n          = ConfigurationManager.AppSettings["NumberOfWorkerThreads"];
            string remoteUrl  = ConfigurationManager.AppSettings["RemoteUrl"];

            connectionString = ConfigurationManager.AppSettings["ConnectionString"];
            inputQueue       = ConfigurationManager.AppSettings["InputQueue"];
            outputQueue      = ConfigurationManager.AppSettings["OutputQueue"];

            int numberOfWorkerThreads = 10;

            int.TryParse(n, out numberOfWorkerThreads);

            ThreadPool.SetMaxThreads(numberOfWorkerThreads, numberOfWorkerThreads);


            messageSender = new MsmqMessageSender {
                UseDeadLetterQueue = true, UseJournalQueue = true
            };

            transport = new TransactionalTransport
            {
                MessageReceiver       = new MsmqMessageReceiver(),
                IsTransactional       = true,
                NumberOfWorkerThreads = numberOfWorkerThreads
            };

            notifier = new MessageNotifier();

            NServiceBus.Configure.Instance.Configurer.RegisterSingleton <ISendMessages>(messageSender);
            NServiceBus.Configure.Instance.Configurer.RegisterSingleton <ITransport>(transport);
            NServiceBus.Configure.Instance.Configurer.RegisterSingleton <INotifyAboutMessages>(notifier);

            transport.TransportMessageReceived += (s, e) =>
            {
                new MsmqHandler(notifier, listenUrl).Handle(e.Message, remoteUrl);

                if (!string.IsNullOrEmpty(audit))
                {
                    messageSender.Send(e.Message, audit);
                }
            };

            listener = new HttpListener();
            listener.Prefixes.Add(listenUrl);
        }