Servers and tools

Resources

csharp.map.sender.cs

usingSystem;usingSystem.Collections.Generic;usingSystem.Collections.ObjectModel;usingOrg.Apache.Qpid.Messaging;namespaceOrg.Apache.Qpid.Messaging.examples{classMapSender{// csharp.map.sender example//// Send an amqp/map message to amqp:tcp:localhost:5672 amq.direct/map_example// The map message contains simple types, a nested amqp/map,// an ampq/list, and specific instances of each supported type.//staticintMain(string[]args){stringurl="amqp:tcp:localhost:5672";stringaddress="message_queue; {create: always}";stringconnectionOptions="";if(args.Length>0)url=args[0];if(args.Length>1)address=args[1];if(args.Length>2)connectionOptions=args[2];//// Create and open an AMQP connection to the broker URL//Connectionconnection=newConnection(url,connectionOptions);connection.Open();//// Create a session and a sender to the direct exchange//Sessionsession=connection.CreateSession();Sendersender=session.CreateSender(address);//// Create structured content for the message. This example builds a// map of items including a nested map and a list of values.//Dictionary<string,object>content=newDictionary<string,object>();Dictionary<string,object>subMap=newDictionary<string,object>();Collection<object>colors=newCollection<object>();// add simple typescontent["id"]=987654321;content["name"]="Widget";content["percent"]=0.99;// add nested amqp/mapsubMap["name"]="Smith";subMap["number"]=354;content["nestedMap"]=subMap;// add an amqp/listcolors.Add("red");colors.Add("green");colors.Add("white");// list contains null valuecolors.Add(null);content["colorsList"]=colors;// add one of each supported amqp data typeboolmybool=true;content["mybool"]=mybool;bytemybyte=4;content["mybyte"]=mybyte;UInt16myUInt16=5;content["myUInt16"]=myUInt16;UInt32myUInt32=6;content["myUInt32"]=myUInt32;UInt64myUInt64=7;content["myUInt64"]=myUInt64;charmychar='h';content["mychar"]=mychar;Int16myInt16=9;content["myInt16"]=myInt16;Int32myInt32=10;content["myInt32"]=myInt32;Int64myInt64=11;content["myInt64"]=myInt64;SinglemySingle=(Single)12.12;content["mySingle"]=mySingle;DoublemyDouble=13.13;content["myDouble"]=myDouble;GuidmyGuid=newGuid("000102030405060708090a0b0c0d0e0f");content["myGuid"]=myGuid;content["myNull"]=null;//// Construct a message with the map content and send it synchronously// via the sender.//Messagemessage=newMessage(content);sender.Send(message,true);//// Wait until broker receives all messages.//session.Sync();//// Close the connection.//connection.Close();return0;}}}