Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added HelloWorld Consumer in C#.

  • Loading branch information...
commit c8a3e901030f83a00de5aea1f65b8808aa9a6f7a 1 parent f8b79c0
Jason J. W. Williams williamsjj authored
53 csharp/appendix-a/HelloWorldConsumer/HelloWorldConsumer.csproj
View
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{783053E0-7DF5-4CFA-B91F-7754D05756AE}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>HelloWorldConsumer</RootNamespace>
+ <AssemblyName>HelloWorldConsumer</AssemblyName>
+ <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkProfile>Client</TargetFrameworkProfile>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Compile Include="hello_world_consumer.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <Reference Include="RabbitMQ.Client, Version=2.7.0.0, Culture=neutral, PublicKeyToken=89e7d7c5feba84ce, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>C:\Program Files\RabbitMQ\DotNetClient\bin\RabbitMQ.Client.dll</HintPath>
+ </Reference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
3  csharp/appendix-a/HelloWorldConsumer/HelloWorldConsumer.csproj.user
View
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+</Project>
20 csharp/appendix-a/HelloWorldConsumer/HelloWorldConsumer.sln
View
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 11.00
+# Visual C# Express 2010
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldConsumer", "HelloWorldConsumer.csproj", "{783053E0-7DF5-4CFA-B91F-7754D05756AE}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {783053E0-7DF5-4CFA-B91F-7754D05756AE}.Debug|x86.ActiveCfg = Debug|x86
+ {783053E0-7DF5-4CFA-B91F-7754D05756AE}.Debug|x86.Build.0 = Debug|x86
+ {783053E0-7DF5-4CFA-B91F-7754D05756AE}.Release|x86.ActiveCfg = Release|x86
+ {783053E0-7DF5-4CFA-B91F-7754D05756AE}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
BIN  csharp/appendix-a/HelloWorldConsumer/HelloWorldConsumer.suo
View
Binary file not shown
63 csharp/appendix-a/HelloWorldConsumer/hello_world_consumer.cs
View
@@ -0,0 +1,63 @@
+/*##############################################
+# RabbitMQ in Action
+# Appendix A- Hello World Consumer (.NET)
+#
+# Requires:
+#
+# Author: Jason J. W. Williams
+# (C)2011
+##############################################*/
+
+using System;
+using System.Text;
+
+using RabbitMQ.Client;
+using RabbitMQ.Client.Events;
+
+namespace HelloWorld {
+ class Consumer {
+
+ public static void Main(string[] args) {
+
+ var conn_factory = new ConnectionFactory();
+
+ // Validate hostname was passed in
+ if(args.Length < 1) {
+ Console.WriteLine("Must supply hostname.");
+ Environment.Exit(-1);
+ }
+
+ conn_factory.HostName = args[0];
+ conn_factory.UserName = "guest";
+ conn_factory.Password = "guest";
+
+ IConnection conn = conn_factory.CreateConnection();
+ IModel chan = conn.CreateModel();
+
+ chan.QueueDeclare("hello-queue", false, false, false, null);
+ chan.ExchangeDeclare("hello-exchange", ExchangeType.Direct, true, false, null);
+ chan.QueueBind("hello-queue", "hello-exchange", "hola");
+
+ QueueingBasicConsumer consumer = new QueueingBasicConsumer(chan);
+ String consumer_tag = chan.BasicConsume("hello-queue", false, consumer);
+
+ while(true) {
+ BasicDeliverEventArgs evt_args = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
+ IBasicProperties msg_props = evt_args.BasicProperties;
+
+ String msg_body = Encoding.ASCII.GetString(evt_args.Body);
+
+ chan.BasicAck(evt_args.DeliveryTag, false);
+
+ if(msg_body == "quit") {
+ chan.BasicCancel(consumer_tag);
+ break;
+ } else
+ Console.WriteLine("Message Body: " + msg_body);
+
+ }
+
+ Environment.Exit(0);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.