コード例 #1
0
ファイル: ReceiveCommand.cs プロジェクト: bmavity/MassTransit
        public ReceiveCommand(IEnumerable <ICommandLineElement> commandLineElements)
        {
            Uri uri = commandLineElements.GetDefinition("uri", x => new Uri(x));

            var transport = TransportCache.GetTransport(uri);

            transport.Receive(message => msg =>
            {
                var data = new byte[message.Length];
                message.Read(data, 0, data.Length);

                string text = Encoding.UTF8.GetString(data);

                Console.WriteLine("Message: " + text);
            });
        }
コード例 #2
0
        public SendTextCommand(IEnumerable <ICommandLineElement> commandLineElements)
        {
            Uri uri = commandLineElements.GetDefinition("uri", x => new Uri(x));

            string message = commandLineElements.GetDefinition("m");

            _log.Info("Sending message " + message + " to " + uri);

            ITransport transport = TransportCache.GetTransport(uri);

            transport.Send(s =>
            {
                var bytes = Encoding.UTF8.GetBytes(message);

                s.Write(bytes, 0, bytes.Length);
            });
        }
コード例 #3
0
ファイル: MoveCommand.cs プロジェクト: bmavity/MassTransit
        public MoveCommand(IEnumerable <ICommandLineElement> commandLineElements)
        {
            Uri from = commandLineElements.GetDefinition("from", x => new Uri(x));
            Uri to   = commandLineElements.GetDefinition("to", x => new Uri(x));


            ITransport fromQueue = TransportCache.GetTransport(from);
            ITransport toQueue   = TransportCache.GetTransport(to);

            fromQueue.Receive(message => msg =>
            {
                var data = new byte[message.Length];
                message.Read(data, 0, data.Length);

                toQueue.Send(x => x.Write(data, 0, data.Length));
            });
        }
コード例 #4
0
ファイル: MoveNCommand.cs プロジェクト: bmavity/MassTransit
        public MoveNCommand(IEnumerable <ICommandLineElement> commandLineElements)
        {
            Uri from = commandLineElements.GetDefinition("from", x => new Uri(x));
            Uri to   = commandLineElements.GetDefinition("to", x => new Uri(x));

            int countOfElementsToMove = commandLineElements.GetDefinition("count", x => Convert.ToInt32(x));

            ITransport fromQueue = TransportCache.GetTransport(from);
            ITransport toQueue   = TransportCache.GetTransport(to);

            IList <byte[]> rawMessageBodies = new List <byte[]>();

            _log.InfoFormat("Attempting to move {0} messages from {1} to {2}.", countOfElementsToMove, from, to);

            for (int i = 1; i <= countOfElementsToMove; i++)
            {
                bool foundMessage   = false;
                int  receiveAttempt = i;
                fromQueue.Receive(message => msg =>
                {
                    var data = new byte[message.Length];
                    message.Read(data, 0, data.Length);
                    rawMessageBodies.Add(data);
                    foundMessage = true;
                    _log.DebugFormat("Receive Attempt {0}: Received message of length {1}.", receiveAttempt, message.Length);
                });

                if (!foundMessage)
                {
                    _log.InfoFormat("After {0} receives. No more messages were found.", i);
                    break;
                }
            }

            _log.InfoFormat("Sending {0} messages to {1}.", rawMessageBodies.Count, to);

            foreach (var messageBody in rawMessageBodies)
            {
                var localMessageBody = messageBody;
                toQueue.Send(x => x.Write(localMessageBody, 0, localMessageBody.Length));
            }
        }
コード例 #5
0
 static TransportCache()
 {
     _instance = new TransportCache();
 }
コード例 #6
0
ファイル: TransportCache.cs プロジェクト: KevM/MassTransit
		static TransportCache()
		{
			_instance = new TransportCache();
		}