本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例6: ToXmlMessage
public static ITextMessage ToXmlMessage(ISession session, object obj)
{
return SerializeObjToMessage(session.CreateTextMessage(), obj);
}
示例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());
}
}
示例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));
}
示例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();
}
示例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);
}
}
}