uint.MaxValue
.
queue.declare
) are allowed to take before
timing out.
IConnectionFactory factory = new ConnectionFactory();
//
// The next six lines are optional:
factory.UserName = ConnectionFactory.DefaultUser;
factory.Password = ConnectionFactory.DefaultPass;
factory.VirtualHost = ConnectionFactory.DefaultVHost;
factory.HostName = hostName;
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
//
IConnection conn = factory.CreateConnection();
//
IModel ch = conn.CreateModel();
//
// ... use ch's IModel methods ...
//
ch.Close(Constants.ReplySuccess, "Closing the channel");
conn.Close(Constants.ReplySuccess, "Closing the connection");
ConnectionFactory factory = new ConnectionFactory();
factory.Uri = "amqp://localhost";
IConnection conn = factory.CreateConnection();
...
queue.declare
) are allowed to take before
timing out.
queue.declare
) are allowed to take before
timing out.
IModel channel = ...;
QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume(queueName, null, consumer);
// At this point, messages will be being asynchronously delivered,
// and will be queueing up in consumer.Queue.
while (true) {
try {
BasicDeliverEventArgs e = (BasicDeliverEventArgs) consumer.Queue.Dequeue();
// ... handle the delivery ...
channel.BasicAck(e.DeliveryTag, false);
} catch (EndOfStreamException ex) {
// The consumer was cancelled, the model closed, or the
// connection went away.
break;
}
}
string queueName = "ServiceRequestQueue"; // See also Subscription ctors
using (IConnection conn = new ConnectionFactory()
.CreateConnection(serverAddress)) {
using (IModel ch = conn.CreateModel()) {
SimpleRpcClient client =
new SimpleRpcClient(ch, queueName);
client.TimeoutMilliseconds = 5000; // optional
/// ... make use of the various Call() overloads
}
}
string queueName = "ServiceRequestQueue"; // See also Subscription ctors
using (IConnection conn = new ConnectionFactory()
.CreateConnection(serverAddress)) {
using (IModel ch = conn.CreateModel()) {
Subscription sub = new Subscription(ch, queueName);
new MySimpleRpcServerSubclass(sub).MainLoop();
}
}
Kludge to compensate for .NET's broken little-endian-only BinaryWriter.
See also NetworkBinaryReader.