コード例 #1
0
ファイル: Client.cs プロジェクト: TobiHatti/EndevFramework
        static void Main(string[] args)
        {
            RMQClient client = new RMQClient("localhost", "RMQClient", "adgjl");

            client.ReceiveEvent(OnReceive);
            client.SelfConsume();
            client.BasicExchanges();

            while (true)
            {
                Thread.Sleep(500);
                client.SendTo($"Hallo von C nach S at {DateTime.Now.ToLongTimeString()}", "LHFullBroadcast", "*");
                Thread.Sleep(500);
                client.SendTo($"Hallo von C nach S at {DateTime.Now.ToLongTimeString()}", "LHFullBroadcast", "*");
            }
        }
コード例 #2
0
ファイル: Client.cs プロジェクト: TobiHatti/EndevFramework
        static void Main(string[] args)
        {
            bool createRMQInfrastructure = true;

            RMQClient client = new RMQClient("localhost", "RMQClient", "adgjl");

            client.ReceiveMessageEvent(OnMessageReceive);
            client.ReceiveRequestEvent(OnRequestReceive);

            if (createRMQInfrastructure)
            {
                client.DeclareExchange("Broadcast", "fanout", true, false);
                client.DeclareExchange("BCPublishers", "fanout", true, false);
                client.DeclareExchange("BCSubscribers", "fanout", true, false);
            }

            client.ExchangeSubscribeSelf("Broadcast");
            client.ExchangeSubscribeSelf("BCSubscribers");

            /* END OF SETUP */
            /* START OF SENDING */

            Thread.Sleep(5000);

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Sending Message to Server...");
                client.SendTo("Hello Server!", "", client.ServerQueue);

                Thread.Sleep(300);
            }

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("Requesting Time from Server...");
                string time = client.RequestFrom("GetTime", client.ServerQueue);
                Console.WriteLine("Reply from Server: " + Convert.ToString(time));

                Thread.Sleep(300);
            }

            /* END OF SENDING */

            Console.ReadLine();
            client.Close();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            // Setting up the Rabbit-MQ Client (Subscriber-Client)
            // • The client receives messages only if it is online.
            //   Messages that get sent to the client get lost when
            //   the client is offline.

            // Initializing the Client (Consumer)
            // On initialization, the client automatically creates a queue AND consumes it.
            RMQClient client = new RMQClient("localhost", "sampleUser", "samplePassword");

            // ====== RMQ-Receive Events ======

            // This handler can send 2 general types of messages:
            // 1) Simple-Messages: Gets sent from A To B, B does not reply and A
            //    does not wait until a reply is received
            // 2) Request-Message: A sends a request to B, B replies to A.
            //    A is halted until the reply is received.
            // Both of the following events need to be set to ensure propper use.

            // To set the receive-event for simple-messages, use
            client.ReceiveMessageEvent(MyMessageReceiveEvent);

            // To set the receive-event for request-messages, use
            client.ReceiveRequestEvent(MyRequestReceiveEvent);

            // ====== Initialising RMQ-Infrastructure ======

            // Define an exchange to distribute messages.
            // Option A) Declare the exchanges once in the RMQ-Management Window (Web-Interface)
            // Option B) Declare the exchange programatically. Doesn't matter if the exchange already exists.
            //           The following line creates an exchange named "Broadcast" which distributes
            //           messages to all connected clients (if they are subscribed to this exchange).
            // The server does not receive messages from this exchange yet.
            client.DeclareExchange("Broadcast", "fanout", true, false);

            // The server already has a queue which gets consumed. if however another queue
            // is required, it can be done as shown below.
            // The following example creates a new queue named "SecondServerQueue".
            // The server does not consume the queue yet.
            client.DeclareQueue("SecondServerQueue", false, false, true);

            // ====== Binding RMQ-Infrastructure ======

            // To get messages from another queue besides the clients own queue,
            // it needs to be consumed by the client:
            client.ConsumeQueue("SecondServerQueue");

            // To receive messages from an exchange (subscribe), it needs to be bound to a queue.
            // To bind the servers own queue to an exchange named "Broadcast", use:
            client.ExchangeSubscribeSelf("Broadcast");

            // To bind another queue to an exchange named "Broadcast", use
            client.ExchangeSubscribe("Broadcast", "SecondServerQueue");

            // *** End of Startup- and Setup-Section ***


            // ====== RMQ-Send Events ======

            // Send a simple message without a reply to a remote node:
            client.SendTo("MyMessageToSend", "Broadcast");

            // Send a request to a remote node. Waits until a reply is received OR the request times out.
            // Default Timeout-Duration is 5 seconds.
            string myReply = client.RequestFrom("MyThingIWantToRequest", "UserIWantToRequestFrom");

            // In case of slow internet-connections, large transfer files or intensive processing
            // at the remote node, the timeout-duration can be increased. Time in Miliseconds
            RMQServer.TimeoutDuration = 10000;


            // ====== Closing an RMQ-Client ======

            // Closing the RMQ-Client is required to properly shut down any existing
            // connections and to avoid errors upon the next start of the program.
            client.Close();


            Console.WriteLine("Done");
        }