本文整理汇总了C#中Amqp.Message.GetBody方法的典型用法代码示例。如果您正苦于以下问题:C# Message.GetBody方法的具体用法?C# Message.GetBody怎么用?C# Message.GetBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amqp.Message
的用法示例。
在下文中一共展示了Message.GetBody方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ContainerHostMessageProcessorTest
public void ContainerHostMessageProcessorTest()
{
string name = MethodInfo.GetCurrentMethod().Name;
var processor = new TestMessageProcessor();
this.host.RegisterMessageProcessor(name, processor);
int count = 500;
var connection = new Connection(Address);
var session = new Session(connection);
var sender = new SenderLink(session, "send-link", name);
for (int i = 0; i < count; i++)
{
var message = new Message("msg" + i);
message.Properties = new Properties() { GroupId = name };
sender.Send(message, SendTimeout);
}
sender.Close();
session.Close();
connection.Close();
Assert.AreEqual(count, processor.Messages.Count);
for (int i = 0; i < count; i++)
{
var message = processor.Messages[i];
Assert.AreEqual("msg" + i, message.GetBody<string>());
}
}
示例2: LargeMessageSendReceiveAsync
public async Task LargeMessageSendReceiveAsync()
{
string testName = "LargeMessageSendReceiveAsync";
int nMsgs = 50;
Connection connection = await Connection.Factory.CreateAsync(
this.testTarget.Address, new Open() { ContainerId = "c1", MaxFrameSize = 4096 }, null);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
int messageSize = 100 * 1024;
for (int i = 0; i < nMsgs; ++i)
{
Message message = new Message(new string('D', messageSize));
message.Properties = new Properties() { MessageId = "msg" + i, GroupId = testName };
message.ApplicationProperties = new ApplicationProperties();
message.ApplicationProperties["sn"] = i;
await sender.SendAsync(message);
}
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
for (int i = 0; i < nMsgs; ++i)
{
Message message = await receiver.ReceiveAsync();
string value = message.GetBody<string>();
Trace.WriteLine(TraceLevel.Information, "receive: {0} body {1}x{2}",
message.ApplicationProperties["sn"], value[0], value.Length);
receiver.Accept(message);
}
await sender.CloseAsync();
await receiver.CloseAsync();
await session.CloseAsync();
await connection.CloseAsync();
}
示例3: LargeMessageOnMessageCallback
public async Task LargeMessageOnMessageCallback()
{
string testName = "LargeMessageOnMessageCallback";
int nMsgs = 50;
Connection connection = await Connection.Factory.CreateAsync(
this.testTarget.Address, new Open() { ContainerId = "c1", MaxFrameSize = 4096 }, null);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
int messageSize = 10 * 1024;
for (int i = 0; i < nMsgs; ++i)
{
Message message = new Message(new string('D', messageSize));
message.Properties = new Properties() { MessageId = "msg" + i, GroupId = testName };
message.ApplicationProperties = new ApplicationProperties();
message.ApplicationProperties["sn"] = i;
sender.Send(message, null, null);
}
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
ManualResetEvent done = new ManualResetEvent(false);
int count = 0;
receiver.Start(30, (link, message) =>
{
string value = message.GetBody<string>();
Trace.WriteLine(TraceLevel.Information, "receive: {0} body {1}x{2}",
message.ApplicationProperties["sn"], value[0], value.Length);
receiver.Accept(message);
if (++count == nMsgs) done.Set();
});
Assert.IsTrue(done.WaitOne(120000));
connection.Close();
}
示例4: OnSendComplete
static void OnSendComplete(Message message, Outcome outcome, object state)
{
var tuple = (Tuple<Sender, SenderLink>)state;
Sender thisPtr = tuple.Item1;
SenderLink sender = tuple.Item2;
if (thisPtr.bufferManager != null)
{
var buffer = message.GetBody<ByteBuffer>();
buffer.Reset();
thisPtr.bufferManager.ReturnBuffer(new ArraySegment<byte>(buffer.Buffer, buffer.Offset, buffer.Capacity));
}
if (thisPtr.OnComplete())
{
Message msg = thisPtr.CreateMessage();
sender.Send(msg, onOutcome, state);
}
}