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


C# ISession.CreateTextMessage方法代码示例

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


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

示例1: ToMessage

 public IMessage ToMessage(object objectToConvert, ISession session)
 {
     if (objectToConvert == null)
     {
         throw new MessageConversionException("Can't convert null object");
     }
     try
     {
         if (objectToConvert.GetType().Equals(typeof (string)) ||
             typeof (IDictionary).IsAssignableFrom(objectToConvert.GetType()) ||
             objectToConvert.GetType().Equals(typeof (Byte[])))
         {
             return defaultMessageConverter.ToMessage(objectToConvert, session);
         }
         else
         {
             string xmlString = GetXmlString(objectToConvert);
             IMessage msg = session.CreateTextMessage(xmlString);
             msg.Properties.SetString(typeMapper.TypeIdFieldName, typeMapper.FromType(objectToConvert.GetType()));
             return msg;
         }
     } catch (Exception e)
     {
         throw new MessageConversionException("Can't convert object of type " + objectToConvert.GetType(), e);
     }
 }
开发者ID:fgq841103,项目名称:spring-net,代码行数:26,代码来源:XmlMessageConverter.cs

示例2: Encode

        public IMessage Encode(TransportMessage message, ISession session)
        {
            var contentType = message.Headers[Headers.ContentType];

            if (contentType == ContentTypes.Json || contentType == ContentTypes.Xml)
            {
                IMessage encoded = session.CreateTextMessage();

                if (message.Body != null)
                {
                    var messageBody = Encoding.UTF8.GetString(message.Body);
                    encoded = session.CreateTextMessage(messageBody);
                }

                return encoded;
            }

            return null;
        }
开发者ID:modulexcite,项目名称:NServiceBus.ActiveMQ,代码行数:19,代码来源:TextMessageEncoder.cs

示例3: CreateEdbDestinationQueueDestination

        object ISessionCallback.DoInNms(ISession session)
        {
            this.log.Debug("Creating destinations...");
            IDestination edbDestination = CreateEdbDestinationQueueDestination(session);
            IDestination responseDestination = CreateEdbResponseQueueDestination(session);

            this.log.Debug("Creating Message to Send");
            ITextMessage msg = session.CreateTextMessage(messageToSend);
            msg.NMSReplyTo = responseDestination;

            this.log.Info("Sending message...");
            session.CreateProducer(edbDestination).Send(msg);
            this.log.Info("Receiving and transforming message...");
            return EngsbMessage.CreateFromXml(((ITextMessage)session.CreateConsumer(responseDestination).Receive()).Text);
        }
开发者ID:bonomat,项目名称:openengsb,代码行数:15,代码来源:EngsbMessageWorker.cs

示例4: TestQueueRollbackConsumerListener

        public void TestQueueRollbackConsumerListener()
        {
            connection.Start();

            this.session = connection.CreateSession(AcknowledgementMode.Transactional);
            ITemporaryQueue queue = session.CreateTemporaryQueue();
            IMessageProducer producer = session.CreateProducer(queue);
            IMessage message = session.CreateTextMessage("Test Message");
            producer.Send(message);
            session.Commit();

            IMessageConsumer consumer = session.CreateConsumer(queue);

            consumer.Listener += new MessageListener(OnMessageListener);

            Thread.Sleep(500);

            // first try.. should get 2 since there is no delay on the
            // first redeliver..
            Assert.AreEqual(2, counter);

            Thread.Sleep(1000);

            // 2nd redeliver (redelivery after 1 sec)
            Assert.AreEqual(3, counter);

            Thread.Sleep(2000);

            // 3rd redeliver (redelivery after 2 seconds) - it should give up after
            // that
            Assert.AreEqual(4, counter);

            // create new message
            producer.Send(session.CreateTextMessage("Test Message Again"));
            session.Commit();

            Thread.Sleep(500);

            // it should be committed, so no redelivery
            Assert.AreEqual(5, counter);

            Thread.Sleep(1500);

            // no redelivery, counter should still be 5
            Assert.AreEqual(5, counter);

            session.Close();
        }
开发者ID:ThorTech,项目名称:apache-nms,代码行数:48,代码来源:MessageListenerRedeliveryTest.cs

示例5: SetUp

        public void SetUp()
        {
            A.Fake<IConnectionFactory>();
            _connection = A.Fake<IConnection>();
            _lazyConnection = new Lazy<IConnection>(() =>
            {
                _connection.Start();
                return _connection;
            });
            _session = A.Fake<ISession>();
            _producer = A.Fake<IMessageProducer>();
            _serializer = A.Fake<IMessageSerializer>();
            _destination = A.Fake<IDestination>();
            _message = A.Fake<ITextMessage>();
            _messagePropertyProvider = A.Fake<IMessagePropertyProvider<IMessage>>();

            A.CallTo(() => _connection.CreateSession(A<Apache.NMS.AcknowledgementMode>.Ignored)).Returns(_session);
            A.CallTo(() => _session.CreateProducer(_destination)).Returns(_producer);
            A.CallTo(() => _session.CreateTextMessage(A<string>._)).Returns(_message);
            A.CallTo(() => _serializer.Serialize(A<object>._)).Returns("SerializedString");

            _testScheduler = new TestScheduler();
            _publisher = new MessagePublisher<IMessage>(_lazyConnection, _destination, _serializer, _messagePropertyProvider, _testScheduler);
        }
开发者ID:ssttgg,项目名称:Obvs.ActiveMQ,代码行数:24,代码来源:TestMessagePublisher.cs

示例6: ToXmlMessage

		public static ITextMessage ToXmlMessage(ISession session, object obj)
		{
			return SerializeObjToMessage(session.CreateTextMessage(), obj);
		}
开发者ID:Redi0,项目名称:meijing-ui,代码行数:4,代码来源:Convert.cs

示例7: btnSetup_Click

                //IDestination destination;
                //        string destinationTarget;
                //switch (cboxDestinationType.SelectedIndex)
                //{
                //    case 0:
                //        destinationTarget = QUEUE_PREFIX + cboxQueueList.Items[cboxQueueList.SelectedIndex] + MAX_INACTIVITY_DURATION;
                //        break;
                //    case 1:
                //        destinationTarget = TOPIC_PREFIX + cboxTopicList.Items[cboxTopicList.SelectedIndex] + MAX_INACTIVITY_DURATION;
                //        break;
                //    default:
                //        throw new Exception("Please select a destination.");
                //}
                //destination = SessionUtil.GetDestination(_session, destinationTarget);

        private void btnSetup_Click(object sender, EventArgs e)
        {
            try
            {
                //TearDown();
                //_connectionFactory = new ConnectionFactory(_connectUri, CLIENT_ID);               
                //_connection = _connectionFactory.CreateConnection(Properties.Settings.Default.MessageServerUserId, Properties.Settings.Default.MessageServerPassword);

                Environment.SetEnvironmentVariable("is.hornetQ.client", "true");
                _connection = CreateConnection();
                _connection.ExceptionListener += new ExceptionListener(OnException);
                _session = _connection.CreateSession(AcknowledgementMode.AutoAcknowledge);

                string destName = cboxTopicList.Text;
                IDestination dest = SessionUtil.GetDestination(_session, TOPIC_PREFIX + destName);
                var consumer = _session.CreateConsumer(dest);
                consumer.Listener += new MessageListener(OnMessage);

                ITextMessage request = _session.CreateTextMessage("Connection verification has been received.");
                
                //request.NMSCorrelationID = "abc";
                //request.Properties["NMSXGroupID"] = "cheese";
                //request.Properties["myHeader"] = "Cheddar";
                using (IMessageProducer producer = _session.CreateProducer(dest))
                {
                    producer.Send(request);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception doing setup: " + "\n" + ex.Message.ToString());
            }
        }
开发者ID:Amphora2015,项目名称:DemoTest,代码行数:48,代码来源:frmTestHornetQ.cs

示例8: CreateMessageForString

 /// <summary> Create a NMS ITextMessage for the given String.</summary>
 /// <param name="text">the String to convert
 /// </param>
 /// <param name="session">current NMS session
 /// </param>
 /// <returns> the resulting message
 /// </returns>
 /// <throws>  NMSException if thrown by NMS methods </throws>
 protected virtual ITextMessage CreateMessageForString(string text, ISession session)
 {
     return session.CreateTextMessage((text));
 }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:12,代码来源:SimpleMessageConverter.cs

示例9: SendMessages

 public void SendMessages(ISession session, IDestination destination, MsgDeliveryMode deliveryMode, int count)
 {
     IMessageProducer producer = session.CreateProducer(destination);
     producer.DeliveryMode = deliveryMode;
     for(int i = 0; i < count; i++)
     {
         producer.Send(session.CreateTextMessage("" + i));
     }
     producer.Close();
 }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:10,代码来源:NMSTestSupport.cs

示例10: PutMsgIntoQueue

 private void PutMsgIntoQueue(ISession session, IDestination destination)
 {
     using(IMessageProducer producer = session.CreateProducer(destination))
     {
         ITextMessage message = session.CreateTextMessage();
         for(int i = 0; i < msgCount; ++i)
         {
             message.Text = "Test message " + (i + 1);
             producer.Send(message);
         }
     }
 }
开发者ID:Redi0,项目名称:meijing-ui,代码行数:12,代码来源:FailoverTransportTest.cs


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