当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionFactory.CreateModel方法代码示例

本文整理汇总了C#中RabbitMQ.Client.ConnectionFactory.CreateModel方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.CreateModel方法的具体用法?C# ConnectionFactory.CreateModel怎么用?C# ConnectionFactory.CreateModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RabbitMQ.Client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.CreateModel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            var serverAddress = "192.168.0.196";
              var queueName = "message_data_cs";

              using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
              {
            using (var ch = conn.CreateModel())
            {
              ch.QueueDeclare(queueName, true);
              var properties = ch.CreateBasicProperties();
              properties.SetPersistent(true);

              for (int i = 0; i < 10; i++)
              {
            var message = new Message()
            {
              From = "C# Sample",
              Body = String.Format("Message No. {0}", i)
            };

            Console.WriteLine("Sending: {0}", i);
            ch.BasicPublish("", queueName, properties, Message.Serialize(message));
              }
            }
              }
        }
开发者ID:antlypls,项目名称:rabbitmq_demos,代码行数:27,代码来源:Program.cs

示例2: WillCreateInputAndErrorQueue

        public void WillCreateInputAndErrorQueue()
        {
            var testRabbitQueues = "test.rabbit.queues";
            CreateBus(testRabbitQueues, new HandlerActivatorForTesting()).Start(1);


            using (var connection = new ConnectionFactory {Uri = ConnectionString}.CreateConnection())
            using (var model = connection.CreateModel())
            {
                Assert.DoesNotThrow(() => model.BasicGet(testRabbitQueues, true));
                Assert.DoesNotThrow(() => model.BasicGet(testRabbitQueues + ".error", true));
            }
        }
开发者ID:nls75,项目名称:Rebus,代码行数:13,代码来源:TestRebusOnRabbit.cs

示例3: DeleteQueue

 public static void DeleteQueue(string queueName)
 {
     using (var connection = new ConnectionFactory {Uri = ConnectionString}.CreateConnection())
     using (var model = connection.CreateModel())
     {
         // just ignore if it fails...
         try
         {
             model.QueueDelete(queueName);
         }
         catch
         {
         }
     }
 }
开发者ID:sTodorov,项目名称:Rebus,代码行数:15,代码来源:RabbitMqFixtureBase.cs

示例4: Main

        static void Main(string[] args)
        {
            var serverAddress = "192.168.0.196";
              var queueName = "string_data";

              using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
              {
            using (var ch = conn.CreateModel())
            {
              var messages = Enumerable.Range(1, 10).Select(x => String.Format("Hello from .NET! Message No. {0}", x));

              foreach (var message in messages)
              {
            Console.WriteLine("Sending: {0}", message);
            ch.BasicPublish("", queueName, null, Encoding.ASCII.GetBytes(message));
              }
            }
              }
        }
开发者ID:antlypls,项目名称:rabbitmq_demos,代码行数:19,代码来源:Program.cs

示例5: Main

        static void Main(string[] args)
        {
            var serverAddress = @"192.168.0.196";
              var queueName = "string_data";

              var conn = new ConnectionFactory().CreateConnection(serverAddress);
              using (var ch = conn.CreateModel())
              {
            conn.AutoClose = true;
            ch.QueueDeclare(queueName);

            BasicGetResult result = null;
            while ((result = ch.BasicGet(queueName, false)) != null)
            {
              ch.BasicAck(result.DeliveryTag, false);
              Console.WriteLine("Message: {0}", Encoding.ASCII.GetString(result.Body));
            }
              }
        }
开发者ID:antlypls,项目名称:rabbitmq_demos,代码行数:19,代码来源:Program.cs

示例6: Main

        static void Main(string[] args)
        {
            var serverAddress = @"192.168.0.196";
              var queueName = "message_data_cs";

              var conn = new ConnectionFactory().CreateConnection(serverAddress);
              using (var ch = conn.CreateModel())
              {
            conn.AutoClose = true;
            ch.QueueDeclare(queueName, true);

            BasicGetResult result = null;
            while ((result = ch.BasicGet(queueName, false)) != null)
            {
              ch.BasicAck(result.DeliveryTag, false);
              var message = Message.Deserialize(result.Body);
              Console.WriteLine(message.Text);
            }
              }

              Console.ReadKey();
        }
开发者ID:antlypls,项目名称:rabbitmq_demos,代码行数:22,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            var serverAddress = "192.168.0.196";
              var queueName = "string_data";

              using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
              {
            using (var ch = conn.CreateModel())
            {
              ch.QueueDeclare(queueName, true);
              var properties = ch.CreateBasicProperties();
              properties.SetPersistent(true);

              for (int i = 0; i < 10; i++)
              {
            var message = String.Format("Hello from .NET! Message No. {0}", i);
            Console.WriteLine("Sending: {0}", message);
            ch.BasicPublish("", queueName, (i % 2 == 1) ? properties : null, Encoding.ASCII.GetBytes(message));
              }
            }
              }
        }
开发者ID:antlypls,项目名称:rabbitmq_demos,代码行数:22,代码来源:Program.cs

示例8: TestRabbitMq

        static void TestRabbitMq(int messageCount)
        {
            IConnection connection = new ConnectionFactory().CreateConnection();

            var serializer = new BinarySerializationStrategy();

            for (int i = 0; i < messageCount; i++)
            {
                IModel model = connection.CreateModel();
                model.ExchangeDeclare("rabbitMQ.test.exchange", ExchangeType.Direct, false, true, null);
                byte[] serializedMessage = serializer.Serialize(new TestMessage("test"));
                model.BasicPublish("rabbitMQ.test.exchange", string.Empty, null, serializedMessage);
                model.Close();
            }

            connection.Close();
        }
开发者ID:derekgreer,项目名称:rabbitBusExamples,代码行数:17,代码来源:Program.cs

示例9: QueueExists

        bool QueueExists(string queueName)
        {
            using (var connection = new ConnectionFactory { Uri = ConnectionString }.CreateConnection())
            {
                using (var model = connection.CreateModel())
                {
                    try
                    {
                        model.QueueDeclarePassive(queueName);

                        // if the call succeeds, then the queue exists
                        return true;
                    }
                    catch (OperationInterruptedException exception)
                    {
                        if (exception.Message.Contains("NOT_FOUND"))
                        {
                            return false;
                        }

                        throw;
                    }
                }
            }
        }
开发者ID:nls75,项目名称:Rebus,代码行数:25,代码来源:TestRabbitMqMessageQueue.cs

示例10: RabbitTransportDoesNotChokeOnMessagesContainingComplexHeaders

        public void RabbitTransportDoesNotChokeOnMessagesContainingComplexHeaders()
        {
            // arrange
            const string recipientInputQueue = "test.roundtripping.receiver";
            const string someText = "whoohaa!";

            DeleteQueue(recipientInputQueue);

            // ensure recipient queue is created...
            using (var recipient = new RabbitMqMessageQueue(ConnectionString, recipientInputQueue))
            {
                // force creation of the queue
                recipient.ReceiveMessage(new NoTransaction());

                // act
                // send a message with a complex header
                using (var connection = new ConnectionFactory { Uri = ConnectionString }.CreateConnection())
                using (var model = connection.CreateModel())
                {
                    var props = model.CreateBasicProperties();
                    props.Headers = new Dictionary<string, object>
                        {
                            {
                                "someKey", new Hashtable
                                    {
                                        {"someContainedKey", "someContainedValue"},
                                        {"anotherContainedKey", "anotherContainedValue"},
                                    }
                            }
                        };

                    model.BasicPublish(recipient.ExchangeName,
                                       recipientInputQueue,
                                       props,
                                       Encoding.GetBytes(someText));
                }

                Thread.Sleep(2.Seconds());

                // assert
                var receivedTransportMessage = recipient.ReceiveMessage(new NoTransaction());
                receivedTransportMessage.ShouldNotBe(null);
                Encoding.GetString(receivedTransportMessage.Body).ShouldBe(someText);
            }

            // assert
        }
开发者ID:nls75,项目名称:Rebus,代码行数:47,代码来源:TestRabbitMqMessageQueue.cs


注:本文中的RabbitMQ.Client.ConnectionFactory.CreateModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。