|
1 | 1 | # Dotnet C# code for RabbitMQ tutorials
|
2 | 2 |
|
3 |
| -Here you can find C# code examples for [RabbitMQ |
| 3 | +Here you can find the C# code examples for [RabbitMQ |
4 | 4 | tutorials](http://www.rabbitmq.com/getstarted.html).
|
5 | 5 |
|
6 |
| -You'll need erlang installed, and also access to a [RabbitMQ server](http://www.rabbitmq.com/server.html). |
7 |
| -These are easy to [install](http://www.rabbitmq.com/install.html). |
8 |
| - |
| 6 | +To successfully use the examples you will need a running RabbitMQ server. |
9 | 7 |
|
10 | 8 | ## Requirements
|
11 | 9 |
|
12 |
| -### Mono on Linux |
| 10 | +### Requirements on Windows |
| 11 | + |
| 12 | +You need the RabbitMQ dotnet client. |
| 13 | + |
| 14 | +* Download [rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip](http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip) |
| 15 | +* Extract it and copy "RabbitMQ.Client.dll" to your working folder. |
| 16 | + |
| 17 | +You also need to ensure your system can find the C# compiler `csc.exe`, |
| 18 | +you may need to add `;C:\WINDOWS\Microsoft.NET\Framework\v3.5` to your |
| 19 | +Path. |
| 20 | + |
| 21 | +We're using the command line (start->run cmd.exe) to |
| 22 | +compile and run the code. Alternatively you could use Visual Studio, but |
| 23 | +due to the nature of examples we prefer the command line. |
| 24 | + |
| 25 | +### Requirements on Linux |
| 26 | + |
13 | 27 | You need Mono and RabbitMQ dotnet client.
|
14 | 28 |
|
15 | 29 | sudo apt-get install mono-devel
|
16 | 30 | mkdir lib
|
17 | 31 | cd lib
|
18 |
| - wget http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.1.1/rabbitmq-dotnet-client-2.1.1-dotnet-3.0.zip |
19 |
| - unzip rabbitmq-dotnet-client-2.1.1-dotnet-3.0.zip |
| 32 | + wget http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.4.1/rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip |
| 33 | + unzip rabbitmq-dotnet-client-2.4.1-dotnet-3.0.zip |
20 | 34 | cd ..
|
21 | 35 |
|
22 |
| - |
23 |
| -### Windows |
24 |
| -You need the RabbitMQ dotnet client. |
25 |
| - |
26 |
| - Go to http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.1.1 |
27 |
| - Download rabbitmq-dotnet-client-2.1.1-dotnet-3.0.zip |
28 |
| - Extract it to rabbitmq-dotnet-client-2.1.1-dotnet-3.0 in your working folder |
29 | 36 |
|
30 |
| - |
31 | 37 | ## Code
|
32 | 38 |
|
33 |
| -For background, you can refer to [Tutorial one: "Hello World!"](http://www.rabbitmq.com/tutorial-one-python.html): |
| 39 | +#### [Tutorial one: "Hello World!"](http://www.rabbitmq.com/tutorial-one-python.html) |
| 40 | + |
| 41 | +##### Windows |
| 42 | + |
| 43 | + csc /r:"RabbitMQ.Client.dll" Send.cs |
| 44 | + csc /r:"RabbitMQ.Client.dll" Receive.cs |
34 | 45 |
|
| 46 | + Send.exe |
| 47 | + Receive.exe |
35 | 48 |
|
36 |
| -### Compile and run the C# examples using Mono on Linux. |
| 49 | +##### Linux |
37 | 50 |
|
38 | 51 | gmcs -r:lib/bin/RabbitMQ.Client.dll Send.cs
|
39 |
| - MONO_PATH=lib/bin mono Send.exe |
40 |
| - |
41 | 52 | gmcs -r:lib/bin/RabbitMQ.Client.dll Receive.cs
|
| 53 | + |
| 54 | + MONO_PATH=lib/bin mono Send.exe |
42 | 55 | MONO_PATH=lib/bin mono Receive.exe
|
43 |
| - |
44 |
| - |
45 |
| -### Compile the C# examples on Windows |
46 | 56 |
|
47 |
| -Ensure your system can find the c# compiler `csc.exe` |
48 | 57 |
|
49 |
| - e.g. Add `;C:\WINDOWS\Microsoft.NET\Framework\v3.5` to your Path |
50 |
| - |
51 |
| -If you put the whole client directory in your working directory: |
| 58 | +#### [Tutorial two: Work Queues](http://www.rabbitmq.com/tutorial-two-python.html) |
52 | 59 |
|
53 |
| - csc /r:".\rabbitmq-dotnet-client-2.1.1-dotnet-3.0\bin\RabbitMQ.Client.dll" Send.cs |
54 |
| - csc /r:".\rabbitmq-dotnet-client-2.1.1-dotnet-3.0\bin\RabbitMQ.Client.dll" Receive.cs |
55 | 60 |
|
56 |
| -or, if you just copy the RabbitMQ.Client.dll client library to your working directory: |
| 61 | +##### Windows |
57 | 62 |
|
58 |
| - csc /r:"RabbitMQ.Client.dll" Send.cs |
59 |
| - csc /r:"RabbitMQ.Client.dll" Receive.cs |
| 63 | + csc /r:"RabbitMQ.Client.dll" NewTask.cs |
| 64 | + csc /r:"RabbitMQ.Client.dll" Worker.cs |
60 | 65 |
|
61 |
| -or you could use MS Visual Studio. |
| 66 | + NewTask.exe |
| 67 | + Worker.exe |
62 | 68 |
|
| 69 | +##### Linux |
63 | 70 |
|
64 |
| -### Run the example programs on Windows |
| 71 | + gmcs -r:lib/bin/RabbitMQ.Client.dll NewTask.cs |
| 72 | + gmcs -r:lib/bin/RabbitMQ.Client.dll Worker.cs |
65 | 73 |
|
66 |
| -Open 3 Command Prompt windows Start > Run... cmd |
| 74 | + MONO_PATH=lib/bin mono NewTask.exe |
| 75 | + MONO_PATH=lib/bin mono Worker.exe |
67 | 76 |
|
68 |
| -Use `rabbitmqctl status` to check the server is running, |
69 |
| -and `rabbitmqctl list_queues` to inspect the queue. |
| 77 | +#### [Tutorial three: Publish/Subscribe](http://www.rabbitmq.com/tutorial-three-python.html) |
70 | 78 |
|
71 |
| -In the other two windows, navigate to your working directory to run the example client programs. |
| 79 | +##### Windows |
72 | 80 |
|
73 |
| -In another cmd window, send a message: |
74 |
| - |
75 |
| - Send.exe |
| 81 | + csc /r:"RabbitMQ.Client.dll" ReceiveLogs.cs |
| 82 | + csc /r:"RabbitMQ.Client.dll" EmitLog.cs |
76 | 83 |
|
77 |
| -Check queue identified as "hello" has 1 message. |
78 |
| -In the final cmd window, set the listener going: |
| 84 | + ReceiveLogs.exe |
| 85 | + EmitLog.exe |
79 | 86 |
|
80 |
| - Receive.exe |
| 87 | +##### Linux |
| 88 | + |
| 89 | + gmcs -r:lib/bin/RabbitMQ.Client.dll ReceiveLogs.cs |
| 90 | + gmcs -r:lib/bin/RabbitMQ.Client.dll EmitLog.cs |
| 91 | + |
| 92 | + MONO_PATH=lib/bin mono ReceiveLogs.exe |
| 93 | + MONO_PATH=lib/bin mono EmitLog.exe |
| 94 | + |
| 95 | +#### [Tutorial four: Routing](http://www.rabbitmq.com/tutorial-four-python.html) |
| 96 | + |
| 97 | +##### Windows |
| 98 | + |
| 99 | + csc /r:"RabbitMQ.Client.dll" ReceiveLogsDirect.cs |
| 100 | + csc /r:"RabbitMQ.Client.dll" EmitLogDirect.cs |
| 101 | + |
| 102 | + ReceiveLogsDirect.exe |
| 103 | + EmitLogDirect.exe |
| 104 | + |
| 105 | +##### Linux |
| 106 | + |
| 107 | + gmcs -r:lib/bin/RabbitMQ.Client.dll ReceiveLogsDirect.cs |
| 108 | + gmcs -r:lib/bin/RabbitMQ.Client.dll EmitLogDirect.cs |
| 109 | + |
| 110 | + MONO_PATH=lib/bin mono ReceiveLogsDirect.exe |
| 111 | + MONO_PATH=lib/bin mono EmitLogDirect.exe |
| 112 | + |
| 113 | +#### [Tutorial five: Topics](http://www.rabbitmq.com/tutorial-five-python.html) |
| 114 | + |
| 115 | +##### Windows |
| 116 | + |
| 117 | + csc /r:"RabbitMQ.Client.dll" ReceiveLogsTopic.cs |
| 118 | + csc /r:"RabbitMQ.Client.dll" EmitLogTopic.cs |
| 119 | + |
| 120 | + ReceiveLogsTopic.exe |
| 121 | + EmitLogTopic.exe |
| 122 | + |
| 123 | +##### Linux |
| 124 | + |
| 125 | + gmcs -r:lib/bin/RabbitMQ.Client.dll ReceiveLogsTopic.cs |
| 126 | + gmcs -r:lib/bin/RabbitMQ.Client.dll EmitLogTopic.cs |
| 127 | + |
| 128 | + MONO_PATH=lib/bin mono ReceiveLogsTopic.exe |
| 129 | + MONO_PATH=lib/bin mono EmitLogTopic.exe |
| 130 | + |
| 131 | +#### [Tutorial six: RPC](http://www.rabbitmq.com/tutorial-six-python.html) |
| 132 | + |
| 133 | +##### Windows |
| 134 | + |
| 135 | + csc /r:"RabbitMQ.Client.dll" RPCServer.cs |
| 136 | + csc /r:"RabbitMQ.Client.dll" RPCClient.cs |
| 137 | + |
| 138 | + RPCServer.exe |
| 139 | + RPCClient.exe |
| 140 | + |
| 141 | +##### Linux |
| 142 | + |
| 143 | + gmcs -r:lib/bin/RabbitMQ.Client.dll RPCServer.cs |
| 144 | + gmcs -r:lib/bin/RabbitMQ.Client.dll RPCClient.cs |
| 145 | + |
| 146 | + MONO_PATH=lib/bin mono RPCServer.exe |
| 147 | + MONO_PATH=lib/bin mono RPCClient.exe |
81 | 148 |
|
82 |
| -This will keep listening (Ctrl-C in this window will stop it) for messages. |
83 |
| -You should now see the first message, and the queue should be empty. |
84 |
| -The Receive view should get any further messages you Send. |
|
0 commit comments