本文整理汇总了C#中Message.GetContent方法的典型用法代码示例。如果您正苦于以下问题:C# Message.GetContent方法的具体用法?C# Message.GetContent怎么用?C# Message.GetContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Message
的用法示例。
在下文中一共展示了Message.GetContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//
// Sample invocation: csharp.example.drain.exe --broker localhost:5672 --timeout 30 my-queue
//
static int Main(string[] args) {
Options options = new Options(args);
Connection connection = null;
try
{
connection = new Connection(options.Url, options.ConnectionOptions);
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(options.Address);
Duration timeout = options.Forever ?
DurationConstants.FORVER :
DurationConstants.SECOND * options.Timeout;
Message message = new Message();
while (receiver.Fetch(ref message, timeout))
{
Dictionary<string, object> properties = new Dictionary<string, object>();
properties = message.Properties;
Console.Write("Message(properties={0}, content='",
message.MapAsString(properties));
if ("amqp/map" == message.ContentType)
{
Dictionary<string, object> content = new Dictionary<string, object>();
message.GetContent(content);
Console.Write(message.MapAsString(content));
}
else if ("amqp/list" == message.ContentType)
{
Collection<object> content = new Collection<object>();
message.GetContent(content);
Console.Write(message.ListAsString(content));
}
else
{
Console.Write(message.GetContent());
}
Console.WriteLine("')");
session.Acknowledge();
}
receiver.Close();
session.Close();
connection.Close();
return 0;
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (null != connection)
connection.Close();
}
return 1;
}
示例2: Main
static void Main(string[] args) {
String broker = args.Length > 0 ? args[0] : "localhost:5672";
String address = args.Length > 1 ? args[1] : "amq.topic";
Connection connection = null;
try {
connection = new Connection(broker);
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(address);
Sender sender = session.CreateSender(address);
sender.Send(new Message("Hello world!"));
Message message = new Message();
message = receiver.Fetch(DurationConstants.SECOND * 1);
Console.WriteLine("{0}", message.GetContent());
session.Acknowledge();
connection.Close();
} catch (Exception e) {
Console.WriteLine("Exception {0}.", e);
if (null != connection)
connection.Close();
}
}
示例3: SimpleMessageStringContent
public void SimpleMessageStringContent()
{
Message m2 = new Message("rarely");
string mString = m2.GetContent();
StringAssert.IsMatch("rarely", mString);
}
示例4: SessionReceiver
// Callback method to be called when message arrives
public void SessionReceiver(Receiver receiver, Message message)
{
Console.WriteLine("RECEIVED MESSAGE:");
Console.WriteLine("#################");
Console.WriteLine("Message text: ", message.GetContent());
Console.WriteLine("Correlation ID: ", message.CorrelationId);
receiver.Session.Acknowledge();
}
示例5: MessageReceiveContentAsByteArray
public void MessageReceiveContentAsByteArray()
{
Message m2 = new Message("while");
UInt64 m2Size = m2.ContentSize;
byte[] myRaw = new byte [m2Size];
m2.GetContent(myRaw);
Assert.IsTrue(true);
}
示例6: SessionReceiver
public void SessionReceiver(Receiver receiver, Message message)
{
try
{
var tradeConfirmationMsg = message.GetContent();
_Log.WarnFormat("Received message : {0}", tradeConfirmationMsg);
var tradeConfirmationDomainModel = TradeConfirmationDM.ParseXML(tradeConfirmationMsg);
if (tradeConfirmationDomainModel.TrdHandlInst != TradeHandlingInstr.Trade_Confirmation)
{
//the received message is not trade confirmation message, log and ingored it
_Log.WarnFormat("The received message is not trade confirmation message, log and ingored it: {0}", tradeConfirmationMsg);
//remove the message from the broadcast queue
//receiver.Session.Acknowledge();
}
}
catch (Exception ex)
{
_Log.Error(string.Format("Process the recived message failed. Message text:{0}, CorreclationID:{1}", message.GetContent(), message.CorrelationId), ex);
}
}
示例7: MessageAsByteArray
public void MessageAsByteArray()
{
byte[] rawData = new byte[10];
for (byte i = 0; i < 10; i++)
rawData[i] = i;
Message m3 = new Message(rawData);
byte[] readback = new byte[m3.ContentSize];
m3.GetContent(readback);
for (byte i = 0; i < 10; i++)
Assert.AreEqual(i, readback[i]);
}
示例8: Main
static int Main(string[] args) {
String url = "amqp:tcp:127.0.0.1:5672";
String connectionOptions = "";
if (args.Length > 0)
url = args[0];
if (args.Length > 1)
connectionOptions = args[1];
Connection connection = new Connection(url, connectionOptions);
try
{
connection.Open();
Session session = connection.CreateSession();
Sender sender = session.CreateSender("service_queue");
Address responseQueue = new Address("#response-queue; {create:always, delete:always}");
Receiver receiver = session.CreateReceiver(responseQueue);
String[] s = new String[] {
"Twas brillig, and the slithy toves",
"Did gire and gymble in the wabe.",
"All mimsy were the borogroves,",
"And the mome raths outgrabe."
};
Message request = new Message("");
request.ReplyTo = responseQueue;
for (int i = 0; i < s.Length; i++) {
request.SetContent(s[i]);
sender.Send(request);
Message response = receiver.Fetch();
Console.WriteLine("{0} -> {1}", request.GetContent(), response.GetContent());
}
connection.Close();
return 0;
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
connection.Close();
}
return 1;
}
示例9: Main
static int Main(string[] args)
{
string url = "amqp:tcp:127.0.0.1:5672";
string connectionOptions = "";
if (args.Length > 0)
url = args[0];
// address args[1] is not used in this example
if (args.Length > 2)
connectionOptions = args[2];
try {
Connection connection = new Connection(url, connectionOptions);
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver("service_queue; {create: always}");
while (true) {
Message request = receiver.Fetch();
Address address = request.ReplyTo;
if (null != address) {
Sender sender = session.CreateSender(address);
String s = request.GetContent();
Message response = new Message(s.ToUpper());
sender.Send(response);
Console.WriteLine("Processed request: {0} -> {1}", request.GetContent(), response.GetContent());
session.Acknowledge();
} else {
Console.WriteLine("Error: no reply address specified for request: {0}", request.GetContent());
session.Reject(request);
}
}
// connection.Close(); // unreachable in this example
} catch (Exception e) {
Console.WriteLine("Exception {0}.", e);
}
return 1;
}
示例10: ShowMessage
/// <summary>
/// A function to diplay a Message. The native Object type is
/// decomposed into AMQP types.
/// </summary>
/// <param name="message">The Message</param>
public static void ShowMessage(Message message)
{
if ("amqp/map" == message.ContentType)
{
Console.WriteLine("Received a Dictionary");
Dictionary<string, object> content = new Dictionary<string, object>();
message.GetContent(content);
ShowDictionary(content, 0);
}
else if ("amqp/list" == message.ContentType)
{
Console.WriteLine("Received a List");
Collection<object> content = new Collection<object>();
message.GetContent(content);
ShowList(content, 0);
}
else
{
Console.WriteLine("Received a String");
Console.WriteLine(message.GetContent());
}
}
示例11: Main
public static void Main(string[] args)
{
string broker_ip = "192.168.0.78:5672";
string data_queue = "fila_dados_ext";
string command_queue = "mxt_command_qpid";
byte[] bMessage = null;
Connection connection = null;
bool response_received = true;
try
{
/*Cria a conexão com o Qpid e abre a sessão sem autenticar*/
connection = new Connection(broker_ip);
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(data_queue + "; {create: always}");
Sender sender = session.CreateSender(command_queue + "; {create: always}");
/*Cria uma nova mensagem e recebe a proxima mensagem da fila se o Fetch()
* não tiver argumentos ele irá esperar a proxima mensagem sem tempo
* definido use (DurationConstants.SECOND * 1) para aguardar 1 segundo*/
while (true)
{
Message message = new Message();
bool message_receive = receiver.Fetch(ref message);
String data_gateway = message.ContentType;
while (message_receive)
{
/*Classe para verificar o tipo da mensagem*/
ConsoleApplication4.Class1 c1 = new ConsoleApplication4.Class1();
ConsoleApplication4.Class1.qpid_subject_type type = c1.get_subject_type(message.Subject);
switch (type)
{
case ConsoleApplication4.Class1.qpid_subject_type.qpid_st_none:
Console.WriteLine("Unknow Message");
break;
case ConsoleApplication4.Class1.qpid_subject_type.qpid_st_pb_mxt1xx_pos:
/*Cria um novo byte array com o tamanho da mensagem*/
bMessage = new byte[message.ContentSize];
/*Escreve o conteudo da mensagem no byte array*/
message.GetContent(bMessage);
/*Constroi o objeto pos_mxt1xx usando o byte array para preenche-lo*/
maxtrack.pb.mxt1xx.mxt1xx_u_position pos_mxt1xx = maxtrack.pb.mxt1xx.mxt1xx_u_position.CreateBuilder().MergeFrom(bMessage).BuildPartial();
Console.Write("Serial: " + pos_mxt1xx.Firmware.Serial + "\n" +
"Memory Index: " + pos_mxt1xx.Firmware.MemoryIndex + "\n" +
"Latitude: " + pos_mxt1xx.GpsModem.Latitude + "\n" +
"Longitude: " + pos_mxt1xx.GpsModem.Longitude + "\n" +
"DATE: " + pos_mxt1xx.GpsModem.Date + "\n" +
"CSQ: " + pos_mxt1xx.GpsModem.Csq + "\n" +
"CellId: " + pos_mxt1xx.CellInfo.CellId + "\n" +
"LocalAreaCode: " + pos_mxt1xx.CellInfo.LocalAreaCode + "\n" +
"NetworkCode: " + pos_mxt1xx.CellInfo.NetworkCode + "\n" +
"CountryCode: " + pos_mxt1xx.CellInfo.CountryCode + "\n" +
"-----------------------------------------" + "\n"
);
/*Campos Optional*/
if (pos_mxt1xx.Firmware.HasLifeTime)
{
Console.WriteLine("Life Time: " + pos_mxt1xx.Firmware.LifeTime + "\n" +
"-----------------------------------------" + "\n");
}
if (response_received)
response_received = mxt1xx_output_control(!pos_mxt1xx.HardwareMonitor.Outputs.Output1, pos_mxt1xx, sender);
break;
case ConsoleApplication4.Class1.qpid_subject_type.qpid_st_pb_command_response:
bMessage = new byte[message.ContentSize];
message.GetContent(bMessage);
maxtrack.pb.commands.u_command_response response = maxtrack.pb.commands.u_command_response.CreateBuilder().MergeFrom(bMessage).BuildPartial();
if (response.Status == 5)
{
Console.WriteLine("Command response: Success");
response_received = true;
}
else
Console.WriteLine("Command response: " + response.Status.ToString());
break;
default:
break;
}
/*Diz ao servidor que a mensagem foi recebida, o servidor apagará a mensagem*/
session.Acknowledge();
message_receive = false;
/*Fecha a conexão*/
//connection.Close();
//System.Threading.Thread.Sleep(1000);
}
}
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
System.Threading.Thread.Sleep(10000);
}
}
示例12: Send
private static void Send()
{
string brokerAddr = "amqp:ssl:chengdudev6:11234";
string failBrokerAddr = "amqp:ssl:chengdudev6:11234";
string memberName = "ABCFR_ABCFRALMMACC1";
string requestAddress = "request." + memberName + "; { node: { type: topic }, create: never }";
string replyAddress = "response/response." + memberName + ".response_queue_1; { create: receiver, node: { type: topic } }";
Connection connection = null;
Session session;
try
{
/*
* Step 1: Preparing the connection and session
*/
connection = new Connection(brokerAddr);
connection.SetOption("reconnect", true);
connection.SetOption("reconnect_limit", 1);
connection.SetOption("reconnect_urls", failBrokerAddr);
connection.SetOption("username", "ABCFR_ABCFRALMMACC1");
connection.SetOption("transport", "ssl");
connection.SetOption("sasl_mechanisms", "EXTERNAL");
connection.Open();
session = connection.CreateSession();
/*
* Step 2: Creating message producer
*/
Sender sender = session.CreateSender(requestAddress);
/*
* Step 3: Sending a message
*/
Message requestMsg = new Message("<FIXML>...</FIXML>");
Address ra = new Address(replyAddress);
requestMsg.ReplyTo = ra;
sender.Send(requestMsg);
Console.WriteLine("Request sent: {0}", requestMsg.GetContent());
session.Sync();
connection.Close();
}
catch (QpidException ex)
{
Console.WriteLine("QpidException caught: {0}", ex.Message);
}
finally
{
if (connection != null && connection.IsOpen)
{
Console.WriteLine("Closing the connection.");
connection.Close();
}
}
}
示例13: ReceiveHelloWorld
private static void ReceiveHelloWorld()
{
String broker = "chengdudev6:21234";
string reseiverAddress = "bxu.testBinding"; //bxu.testBinging was binded to exchange "amq.topic"
Connection connection = null;
try
{
connection = new Connection(broker);
connection.SetOption("username", "admin");
connection.SetOption("password", "admin");
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(reseiverAddress);
Message message = new Message();
message = receiver.Fetch(DurationConstants.SECOND * 1);
Console.WriteLine("{0}", message.GetContent());
//The message should be acknowledged after its processing is finished.
session.Acknowledge();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (connection != null)
connection.Close();
}
}
示例14: SendReceiveBindingHelloWord
private static void SendReceiveBindingHelloWord()
{
//or start simpe qpid on windows :
//cmd: qpidd --port=60302 --no-data-dir --auth=no
String broker = "chengdudev6:21234";
String senderAddress = "amq.topic"; // queue "bxu.testBinding" was binded to this exchange
string reseiverAddress = "bxu.testBinding";
Connection connection = null;
try
{
connection = new Connection(broker);
connection.SetOption("username", "admin");
connection.SetOption("password", "admin");
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(reseiverAddress);
Sender sender = session.CreateSender(senderAddress);
sender.Send(new Message("<FIXML>........</FIXML>"));
Message message = new Message();
message = receiver.Fetch(DurationConstants.SECOND * 1);
Console.WriteLine("{0}", message.GetContent());
session.Acknowledge();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (connection != null)
connection.Close();
}
}
示例15: SendReceiveHelloWord_SSL
private static void SendReceiveHelloWord_SSL()
{
//or start simpe qpid on windows :
//cmd: qpidd --port=60302 --no-data-dir --auth=no
String broker = "amqp:ssl:chengdudev6:11234";
String address = "amq.topic"; // queue "bxu.testBinding" was binded to this exchange
Connection connection = null;
try
{
connection = new Connection(broker);
connection.SetOption("username", "ABCFR_ABCFRALMMACC1");
connection.SetOption("transport", "ssl");
connection.SetOption("sasl_mechanisms", "EXTERNAL");
connection.Open();
Session session = connection.CreateSession();
Receiver receiver = session.CreateReceiver(address);
Sender sender = session.CreateSender(address);
sender.Send(new Message("<FIXML>........</FIXML>"));
Message message = new Message();
message = receiver.Fetch(DurationConstants.SECOND * 1);
Console.WriteLine("{0}", message.GetContent());
session.Acknowledge();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (connection != null)
connection.Close();
}
}