本文整理汇总了C#中Amqp.Message类的典型用法代码示例。如果您正苦于以下问题:C# Message类的具体用法?C# Message怎么用?C# Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于Amqp命名空间,在下文中一共展示了Message类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: DeclareAsync
public Task<byte[]> DeclareAsync()
{
Message message = new Message(new Declare());
TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
this.Send(message, null, OnOutcome, tcs);
return tcs.Task;
}
开发者ID:chrisriesgo,项目名称:mini-hacks,代码行数:7,代码来源:Controller.cs
示例2: WebSocketSendReceiveAsync
public async Task WebSocketSendReceiveAsync()
{
string testName = "WebSocketSendReceiveAsync";
// assuming it matches the broker's setup and port is not taken
Address wsAddress = new Address("ws://guest:[email protected]:18080");
int nMsgs = 50;
Connection connection = await Connection.Factory.CreateAsync(wsAddress);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, "q1");
for (int i = 0; i < nMsgs; ++i)
{
Message message = new Message();
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, "q1");
for (int i = 0; i < nMsgs; ++i)
{
Message message = await receiver.ReceiveAsync();
Trace.WriteLine(TraceLevel.Information, "receive: {0}", message.ApplicationProperties["sn"]);
receiver.Accept(message);
}
await sender.CloseAsync();
await receiver.CloseAsync();
await session.CloseAsync();
await connection.CloseAsync();
}
开发者ID:noodlefrenzy,项目名称:amqpnetlite,代码行数:34,代码来源:WebSocketTests.cs
示例3: DischargeAsync
public Task DischargeAsync(byte[] txnId, bool fail)
{
Message message = new Message(new Discharge() { TxnId = txnId, Fail = fail });
TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
this.Send(message, null, OnOutcome, tcs);
return tcs.Task;
}
开发者ID:chrisriesgo,项目名称:mini-hacks,代码行数:7,代码来源:Controller.cs
示例4: RunRequestClient
static void RunRequestClient(string address)
{
Connection connection = new Connection(new Address(address));
Session session = new Session(connection);
string replyTo = "client-reply-to";
Attach recvAttach = new Attach()
{
Source = new Source() { Address = "request_processor" },
Target = new Target() { Address = replyTo }
};
ReceiverLink receiver = new ReceiverLink(session, "request-client-receiver", recvAttach, null);
SenderLink sender = new SenderLink(session, "request-client-sender", "request_processor");
Message request = new Message("hello");
request.Properties = new Properties() { MessageId = "request1", ReplyTo = replyTo };
sender.Send(request, null, null);
Console.WriteLine("Sent request {0} body {1}", request.Properties, request.Body);
Message response = receiver.Receive();
Console.WriteLine("Received response: {0} body {1}", response.Properties, response.Body);
receiver.Accept(response);
receiver.Close();
sender.Close();
session.Close();
connection.Close();
}
开发者ID:helljai,项目名称:amqpnetlite,代码行数:29,代码来源:Program.cs
示例5: ReplyAsync
async Task ReplyAsync(RequestContext requestContext)
{
if (this.offset == 0)
{
this.offset = (int)requestContext.Message.ApplicationProperties["offset"];
}
while (this.offset < 1000)
{
try
{
Message response = new Message("reply" + this.offset);
response.ApplicationProperties = new ApplicationProperties();
response.ApplicationProperties["offset"] = this.offset;
requestContext.ResponseLink.SendMessage(response);
this.offset++;
}
catch (Exception exception)
{
Console.WriteLine("Exception: " + exception.Message);
if (requestContext.State == ContextState.Aborted)
{
Console.WriteLine("Request is aborted. Last offset: " + this.offset);
return;
}
}
await Task.Delay(1000);
}
requestContext.Complete(new Message("done"));
}
开发者ID:Eclo,项目名称:amqpnetlite,代码行数:32,代码来源:Program.cs
示例6: SendAsync
/// <summary>
/// Sends a message asynchronously.
/// </summary>
/// <param name="sender">The link.</param>
/// <param name="message">The message.</param>
/// <returns></returns>
public static async Task SendAsync(this SenderLink sender, Message message)
{
var txnState = await TaskExtensions.GetTransactionalStateAsync(sender);
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
sender.Send(
message,
txnState,
(m, o, s) =>
{
var t = (TaskCompletionSource<object>)s;
if (o.Descriptor.Code == Codec.Accepted.Code)
{
t.SetResult(null);
}
else if (o.Descriptor.Code == Codec.Rejected.Code)
{
t.SetException(new AmqpException(((Rejected)o).Error));
}
else
{
t.SetException(new AmqpException(ErrorCode.InternalError, o.Descriptor.Name));
}
},
tcs);
await tcs.Task;
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:34,代码来源:TaskExtensions.cs
示例7: TestMethod_BasicSendReceive
public void TestMethod_BasicSendReceive()
{
string testName = "BasicSendReceive";
const int nMsgs = 200;
Connection connection = new Connection(testTarget.Address);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);
for (int i = 0; i < nMsgs; ++i)
{
Message message = new Message("msg" + i);
message.Properties = new Properties() { GroupId = "abcdefg" };
message.ApplicationProperties = new ApplicationProperties();
message.ApplicationProperties["sn"] = i;
sender.Send(message, null, null);
}
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);
for (int i = 0; i < nMsgs; ++i)
{
Message message = receiver.Receive();
Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.ApplicationProperties["sn"]);
receiver.Accept(message);
}
sender.Close();
receiver.Close();
session.Close();
connection.Close();
}
开发者ID:Azure,项目名称:amqpnetlite,代码行数:30,代码来源:LinkTests.cs
示例8: CustomMessgeBody
public async Task CustomMessgeBody()
{
string testName = "CustomMessgeBody";
Connection connection = await Connection.Factory.CreateAsync(this.address);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, "q1");
Student student = new Student("Tom");
student.Age = 16;
student.Address = new StreetAddress() { FullAddress = "100 Main St. Small Town" };
student.DateOfBirth = new System.DateTime(1988, 5, 1, 1, 2, 3, 100, System.DateTimeKind.Utc);
Message message = new Message(student);
message.Properties = new Properties() { MessageId = "student" };
await sender.SendAsync(message);
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "q1");
Message message2 = await receiver.ReceiveAsync();
Trace.WriteLine(TraceLevel.Information, "receive: {0}", message2.Properties);
receiver.Accept(message);
await sender.CloseAsync();
await receiver.CloseAsync();
await session.CloseAsync();
await connection.CloseAsync();
Student student2 = message2.GetBody<Student>();
Assert.AreEqual(student.Age, student2.Age - 1); // incremented in OnDeserialized
Assert.AreEqual(student.DateOfBirth, student2.DateOfBirth);
Assert.AreEqual(student.Address.FullAddress, student2.Address.FullAddress);
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:32,代码来源:TaskTests.cs
示例9: TransactedPosting
public void TransactedPosting()
{
string testName = "TransactedPosting";
int nMsgs = 5;
Connection connection = new Connection(this.address);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-" + testName, "q1");
// commit
using (var ts = new TransactionScope())
{
for (int i = 0; i < nMsgs; i++)
{
Message message = new Message("test");
message.Properties = new Properties() { MessageId = "commit" + i, GroupId = testName };
sender.Send(message);
}
ts.Complete();
}
// rollback
using (var ts = new TransactionScope())
{
for (int i = nMsgs; i < nMsgs * 2; i++)
{
Message message = new Message("test");
message.Properties = new Properties() { MessageId = "rollback" + i, GroupId = testName };
sender.Send(message);
}
}
// commit
using (var ts = new TransactionScope())
{
for (int i = 0; i < nMsgs; i++)
{
Message message = new Message("test");
message.Properties = new Properties() { MessageId = "commit" + i, GroupId = testName };
sender.Send(message);
}
ts.Complete();
}
ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, "q1");
for (int i = 0; i < nMsgs * 2; i++)
{
Message message = receiver.Receive();
Trace.WriteLine(TraceLevel.Information, "receive: {0}", message.Properties.MessageId);
receiver.Accept(message);
Assert.IsTrue(message.Properties.MessageId.StartsWith("commit"));
}
connection.Close();
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:57,代码来源:TransactionTests.cs
示例10: PrintMessage
static void PrintMessage(Message message)
{
if (message.Header != null) Console.WriteLine(message.Header.ToString());
if (message.DeliveryAnnotations != null) Console.WriteLine(message.DeliveryAnnotations.ToString());
if (message.MessageAnnotations != null) Console.WriteLine(message.MessageAnnotations.ToString());
if (message.Properties != null) Console.WriteLine(message.Properties.ToString());
if (message.ApplicationProperties != null) Console.WriteLine(message.ApplicationProperties.ToString());
if (message.BodySection != null) Console.WriteLine("body:{0}", message.Body.ToString());
if (message.Footer != null) Console.WriteLine(message.Footer.ToString());
}
开发者ID:helljai,项目名称:amqpnetlite,代码行数:10,代码来源:Program.cs
示例11: BrokeredMessage
/// <summary>
/// Constructor from an AMQP message
/// </summary>
/// <param name="amqpMessage">AMQP message</param>
internal BrokeredMessage(Message amqpMessage)
: this()
{
if (amqpMessage == null)
throw new ArgumentNullException("amqpMessage");
MessageConverter.AmqpMessageToBrokeredMessage(amqpMessage, this);
this.bodyStream = (amqpMessage.Body != null) ? new MemoryStream((byte[])amqpMessage.Body) : null;
}
开发者ID:Tawnos,项目名称:azuresblite,代码行数:14,代码来源:BrokeredMessage.cs
示例12: Main
//
// Sample invocation: Interop.Spout.exe --broker localhost:5672 --timeout 30 --address my-queue
//
static int Main(string[] args)
{
const int ERROR_SUCCESS = 0;
const int ERROR_OTHER = 2;
int exitCode = ERROR_SUCCESS;
Connection connection = null;
try
{
Options options = new Options(args);
Address address = new Address(options.Url);
connection = new Connection(address);
Session session = new Session(connection);
SenderLink sender = new SenderLink(session, "sender-spout", options.Address);
// TODO: ReplyTo
Stopwatch stopwatch = new Stopwatch();
TimeSpan timespan = new TimeSpan(0, 0, options.Timeout);
stopwatch.Start();
for (int nSent = 0;
(0 == options.Count || nSent < options.Count) &&
(0 == options.Timeout || stopwatch.Elapsed <= timespan);
nSent++)
{
string id = options.Id;
if (id.Equals(""))
{
Guid g = Guid.NewGuid();
id = g.ToString();
}
id += ":" + nSent.ToString();
Message message = new Message(options.Content);
message.Properties = new Properties() { MessageId = id };
sender.Send(message);
if (options.Print)
{
Console.WriteLine("Message(Properties={0}, ApplicationProperties={1}, Body={2}",
message.Properties, message.ApplicationProperties, message.Body);
}
}
sender.Close();
session.Close();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (null != connection)
connection.Close();
exitCode = ERROR_OTHER;
}
return exitCode;
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:58,代码来源:Interop.Spout.cs
示例13: SendMessages
void SendMessages(int count)
{
for (int i = 0; i < count; ++i)
{
Message message = new Message("hello");
message.Properties = new Properties() { MessageId = "msg" + i, GroupId = "perf" };
message.ApplicationProperties = new ApplicationProperties();
message.ApplicationProperties["sn"] = i;
this.sender.Send(message, onOutcome, this);
}
}
开发者ID:Eclo,项目名称:amqpnetlite,代码行数:11,代码来源:PerfTests.cs
示例14: Main
//
// Sample invocation: Interop.Drain.exe --broker localhost:5672 --timeout 30 --address my-queue
//
static int Main(string[] args)
{
const int ERROR_SUCCESS = 0;
const int ERROR_NO_MESSAGE = 1;
const int ERROR_OTHER = 2;
int exitCode = ERROR_SUCCESS;
Connection connection = null;
try
{
Options options = new Options(args);
Address address = new Address(options.Url);
connection = new Connection(address);
Session session = new Session(connection);
ReceiverLink receiver = new ReceiverLink(session, "receiver-drain", options.Address);
int timeout = int.MaxValue;
if (!options.Forever)
timeout = 1000 * options.Timeout;
Message message = new Message();
int nReceived = 0;
receiver.SetCredit(options.InitialCredit);
while ((message = receiver.Receive(timeout)) != null)
{
nReceived++;
if (!options.Quiet)
{
Console.WriteLine("Message(Properties={0}, ApplicationProperties={1}, Body={2}",
message.Properties, message.ApplicationProperties, message.Body);
}
receiver.Accept(message);
if (options.Count > 0 && nReceived == options.Count)
{
break;
}
}
if (message == null)
{
exitCode = ERROR_NO_MESSAGE;
}
receiver.Close();
session.Close();
connection.Close();
}
catch (Exception e)
{
Console.WriteLine("Exception {0}.", e);
if (null != connection)
connection.Close();
exitCode = ERROR_OTHER;
}
return exitCode;
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:56,代码来源:Interop.Drain.cs
示例15: GetPartitions
protected void GetPartitions(Session session)
{
ReceiverLink receiverLink = null;
SenderLink senderLink = null;
try
{
// create a pair of links for request/response
Trace.WriteLine(TraceLevel.Information, "Creating a request and a response link...");
string clientNode = "client-temp-node";
senderLink = new SenderLink(session, "mgmt-sender", "$management");
receiverLink = new ReceiverLink(
session,
"mgmt-receiver",
new Attach()
{
Source = new Source() { Address = "$management" },
Target = new Target() { Address = clientNode }
},
null);
var request = new Amqp.Message();
request.Properties = new Properties() { MessageId = "request1", ReplyTo = clientNode };
request.ApplicationProperties = new ApplicationProperties();
request.ApplicationProperties["operation"] = "READ";
request.ApplicationProperties["name"] = settings.EventHubName;
request.ApplicationProperties["type"] = "com.microsoft:eventhub";
senderLink.Send(request, null, null);
var response = receiverLink.Receive(15000); // time out after 15 seconds
if (response == null)
{
throw new Exception("No get partitions response was received.");
}
receiverLink.Accept(response);
Trace.WriteLine(TraceLevel.Information, "Partition info {0}", response.Body.ToString());
var partitionStrings = (string[])((Map)response.Body)["partition_ids"];
Trace.WriteLine(TraceLevel.Information, "Partitions {0}", string.Join(",", partitionStrings));
this.partitions = new List<string>(partitionStrings);
}
catch (Exception x)
{
Trace.WriteLine(TraceLevel.Error, "Error retrieving partitions:\r\n{0}", x.ToString());
throw x;
}
finally
{
if (receiverLink != null) receiverLink.Close();
if (senderLink != null) senderLink.Close();
}
}
开发者ID:fredfourie,项目名称:Argonaut,代码行数:53,代码来源:EventHubClient.cs
示例16: OnSendComplete
static void OnSendComplete(Message m, Outcome o, object state)
{
PerfTests thisPtr = (PerfTests)state;
int sentCount = Interlocked.Increment(ref thisPtr.completedCount);
if (sentCount >= thisPtr.totalCount)
{
thisPtr.done.Set();
}
else if (sentCount % thisPtr.batchCount == 0)
{
thisPtr.SendMessages(thisPtr.batchCount);
}
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:13,代码来源:PerfTests.cs
示例17: GetPartitions
static string[] GetPartitions()
{
Trace.WriteLine(TraceLevel.Information, "Retrieving partitions...");
Trace.WriteLine(TraceLevel.Information, "Establishing a connection...");
Address address = new Address(sbNamespace, 5671, keyName, keyValue);
Connection connection = new Connection(address);
Trace.WriteLine(TraceLevel.Information, "Creating a session...");
Session session = new Session(connection);
// create a pair of links for request/response
Trace.WriteLine(TraceLevel.Information, "Creating a request and a response link...");
string clientNode = "client-temp-node";
SenderLink sender = new SenderLink(session, "mgmt-sender", "$management");
ReceiverLink receiver = new ReceiverLink(
session,
"mgmt-receiver",
new Attach()
{
Source = new Source() { Address = "$management" },
Target = new Target() { Address = clientNode }
},
null);
Message request = new Message();
request.Properties = new Properties() { MessageId = "request1", ReplyTo = clientNode };
request.ApplicationProperties = new ApplicationProperties();
request.ApplicationProperties["operation"] = "READ";
request.ApplicationProperties["name"] = entity;
request.ApplicationProperties["type"] = "com.microsoft:eventhub";
sender.Send(request, null, null);
Message response = receiver.Receive();
if (response == null)
{
throw new Exception("No response was received.");
}
receiver.Accept(response);
receiver.Close();
sender.Close();
connection.Close();
Trace.WriteLine(TraceLevel.Information, "Partition info {0}", response.Body.ToString());
string[] partitions = (string[])((Map)response.Body)["partition_ids"];
Trace.WriteLine(TraceLevel.Information, "Partitions {0}", string.Join(",", partitions));
Trace.WriteLine(TraceLevel.Information, "");
return partitions;
}
开发者ID:timhermann,项目名称:amqpnetlite,代码行数:50,代码来源:Program.cs
示例18: SendMessageToDevice
public async Task SendMessageToDevice(string messageToDevice)
{
var sender = new SenderLink(session, "sender-link", "/messages/devicebound");
var message = new Message(System.Text.Encoding.UTF8.GetBytes(messageToDevice));
message.Properties = new Properties();
message.Properties.To = $"/devices/{Constants.DeviceId}/messages/devicebound";
message.Properties.MessageId = Guid.NewGuid().ToString();
message.ApplicationProperties = new ApplicationProperties();
message.ApplicationProperties["iothub-ack"] = "full";
await sender.SendAsync(message);
await sender.CloseAsync();
}
开发者ID:xamarin,项目名称:mini-hacks,代码行数:14,代码来源:SmartCoffeeService.cs
示例19: PutTokenAsync
async Task PutTokenAsync(Connection connection)
{
var session = new Session(connection);
string cbsClientAddress = "cbs-client-reply-to";
var cbsSender = new SenderLink(session, "cbs-sender", "$cbs");
var receiverAttach = new Attach()
{
Source = new Source() { Address = "$cbs" },
Target = new Target() { Address = cbsClientAddress }
};
var cbsReceiver = new ReceiverLink(session, "cbs-receiver", receiverAttach, null);
var sasToken = GetSASToken(this.KeyName, this.KeyValue, string.Format("http://{0}/{1}", this.Namespace, this.Entity), TimeSpan.FromMinutes(20));
Trace.WriteLine(TraceLevel.Information, " sas token: {0}", sasToken);
// construct the put-token message
var request = new Message(sasToken);
request.Properties = new Properties();
request.Properties.MessageId = "1";
request.Properties.ReplyTo = cbsClientAddress;
request.ApplicationProperties = new ApplicationProperties();
request.ApplicationProperties["operation"] = "put-token";
request.ApplicationProperties["type"] = "servicebus.windows.net:sastoken";
request.ApplicationProperties["name"] = string.Format("amqp://{0}/{1}", this.Namespace, this.Entity);
await cbsSender.SendAsync(request);
Trace.WriteLine(TraceLevel.Information, " request: {0}", request.Properties);
Trace.WriteLine(TraceLevel.Information, " request: {0}", request.ApplicationProperties);
// receive the response
var response = await cbsReceiver.ReceiveAsync();
if (response == null || response.Properties == null || response.ApplicationProperties == null)
{
throw new Exception("invalid response received");
}
// validate message properties and status code.
Trace.WriteLine(TraceLevel.Information, " response: {0}", response.Properties);
Trace.WriteLine(TraceLevel.Information, " response: {0}", response.ApplicationProperties);
int statusCode = (int)response.ApplicationProperties["status-code"];
if (statusCode != (int)HttpStatusCode.Accepted && statusCode != (int)HttpStatusCode.OK)
{
throw new Exception("put-token message was not accepted. Error code: " + statusCode);
}
// the sender/receiver may be kept open for refreshing tokens
await cbsSender.CloseAsync();
await cbsReceiver.CloseAsync();
await session.CloseAsync();
}
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:49,代码来源:CbsAsyncExample.cs
示例20: WriteAsync
public Task WriteAsync(string messageToSend)
{
return (Task.Run(() =>
{
// not sure where the async went?
var message = new Message()
{
BodySection = new Data()
{
Binary = Encoding.UTF8.GetBytes(messageToSend)
}
};
this.senderLink.Value.Send(message);
}));
}
开发者ID:abhaybagai,项目名称:DataCultureSeries,代码行数:15,代码来源:EventHubWriter.cs
注:本文中的Amqp.Message类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论