本文整理汇总了C#中MessageProperties类的典型用法代码示例。如果您正苦于以下问题:C# MessageProperties类的具体用法?C# MessageProperties怎么用?C# MessageProperties使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageProperties类属于命名空间,在下文中一共展示了MessageProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_be_able_to_write_debug_properties
public void Should_be_able_to_write_debug_properties()
{
const string expectedDebugProperties =
"ContentType=content_type, ContentEncoding=content_encoding, " +
"Headers=[key1=value1, key2=value2], DeliveryMode=10, Priority=3, CorrelationId=NULL, " +
"ReplyTo=reply_to, Expiration=expiration, MessageId=message_id, Timestamp=123456, Type=type, " +
"UserId=userid, AppId=app_id, ClusterId=cluster_id";
var stringBuilder = new StringBuilder();
var headers = new Dictionary<string, object>
{
{"key1", "value1"},
{"key2", "value2"}
};
var properties = new MessageProperties
{
AppId = "app_id",
ClusterId = "cluster_id",
ContentEncoding = "content_encoding",
ContentType = "content_type",
//CorrelationId = "correlation_id",
DeliveryMode = 10,
Expiration = "expiration",
Headers = headers,
MessageId = "message_id",
Priority = 3,
ReplyTo = "reply_to",
Timestamp = 123456,
Type = "type",
UserId = "userid",
};
properties.ToString().ShouldEqual(expectedDebugProperties);
}
示例2: AmfMessageBase
/// <summary>
/// Constructor.
/// </summary>
protected AmfMessageBase()
{
_properties = new MessageProperties();
//Make sure that there is no wrapping applied to this message
_headers = new MessageHeaders(MessageVersion.None);
}
示例3: OldSendMessages
private void OldSendMessages(RabbitTemplate template)
{
IBasicProperties basicProperties = template.Execute<IBasicProperties>(delegate(IModel model)
{
return model.CreateBasicProperties();
});
/*
* System.ArgumentNullException: String reference not set to an instance of a String.
Parameter name: s
at System.Text.Encoding.GetBytes(String s)
at RabbitMQ.Client.Impl.WireFormatting.WriteShortstr(NetworkBinaryWriter writer, String val)
*/
IMessageProperties messageProperties = new MessageProperties(basicProperties);
//write all short props
messageProperties.ContentType = "text/plain";
messageProperties.ContentEncoding = "UTF-8";
messageProperties.CorrelationId = Encoding.UTF8.GetBytes("corr1");
messageProperties.DeliveryMode = MessageDeliveryMode.PERSISTENT;
messageProperties.Priority = 0;
byte[] byteMessage = Encoding.UTF8.GetBytes("testing");
template.Send("amq.direct", "foo", delegate
{
Message msg = new Message(byteMessage, messageProperties);
Console.WriteLine("sending...");
return msg;
});
//template.Send("amq.direct", "foo", channel => new Message(Encoding.UTF8.GetBytes("testing"), messageProperties));
}
示例4: PublishedMessageEvent
public PublishedMessageEvent(string exchangeName, string routingKey, MessageProperties properties, byte[] body)
{
ExchangeName = exchangeName;
RoutingKey = routingKey;
Properties = properties;
Body = body;
}
示例5: EchoHttpRequestMessageProperty
public TestHttpRequestMessageProperty EchoHttpRequestMessageProperty()
{
object obj;
MessageProperties properties = new MessageProperties(OperationContext.Current.IncomingMessageProperties);
if (properties.TryGetValue(HttpRequestMessageProperty.Name, out obj))
{
HttpRequestMessageProperty property = (HttpRequestMessageProperty)obj;
if (property != null)
{
TestHttpRequestMessageProperty testProperty = new TestHttpRequestMessageProperty();
testProperty.SuppressEntityBody = property.SuppressEntityBody;
testProperty.Method = property.Method;
testProperty.QueryString = property.QueryString;
WebHeaderCollection collection = property.Headers;
foreach (string s in collection.AllKeys)
{
string[] values = collection.GetValues(s);
testProperty.Headers.Add(s, String.Join(",", values));
}
return testProperty;
}
}
return null;
}
示例6: AdwsRequestMsg
protected AdwsRequestMsg(string instance)
{
this._messageProperties = new MessageProperties();
this._messageHeaders = new MessageHeaders(this.Version, 7);
this.Headers.Action = this.Action;
this.Headers.Add(MessageHeader.CreateHeader("instance", "http://schemas.microsoft.com/2008/1/ActiveDirectory", instance));
}
示例7: AckEvent
public AckEvent(MessageReceivedInfo info, MessageProperties properties, byte[] body , AckResult ackResult)
{
ReceivedInfo = info;
Properties = properties;
Body = body;
AckResult = ackResult;
}
示例8: GetMessagesFromQueue
public IEnumerable<HosepipeMessage> GetMessagesFromQueue(QueueParameters parameters)
{
using (var connection = HosepipeConnection.FromParamters(parameters))
using (var channel = connection.CreateModel())
{
try
{
channel.QueueDeclarePassive(parameters.QueueName);
}
catch (OperationInterruptedException exception)
{
Console.WriteLine(exception.Message);
yield break;
}
var count = 0;
while (count++ < parameters.NumberOfMessagesToRetrieve)
{
var basicGetResult = channel.BasicGet(parameters.QueueName, noAck: parameters.Purge);
if (basicGetResult == null) break; // no more messages on the queue
var properties = new MessageProperties(basicGetResult.BasicProperties);
var info = new MessageReceivedInfo(
"hosepipe",
basicGetResult.DeliveryTag,
basicGetResult.Redelivered,
basicGetResult.Exchange,
basicGetResult.RoutingKey,
parameters.QueueName);
yield return new HosepipeMessage(errorMessageSerializer.Serialize(basicGetResult.Body), properties, info);
}
}
}
示例9: ValidateMessagePropertyHeaders
public Dictionary<string, string> ValidateMessagePropertyHeaders()
{
Dictionary<string, string> headerCollection = new Dictionary<string, string>();
try
{
HttpRequestMessageProperty property;
object obj;
MessageProperties properties = new MessageProperties(OperationContext.Current.IncomingMessageProperties);
if (properties.TryGetValue(HttpRequestMessageProperty.Name, out obj))
{
property = obj as HttpRequestMessageProperty;
WebHeaderCollection collection = property.Headers;
string[] headers = collection.AllKeys;
foreach (string s in headers)
{
string[] values = collection.GetValues(s);
headerCollection.Add(s, String.Join(",", values));
}
}
else
{
headerCollection.Add("ERROR", "No HttpRequestMessageProperty was found!");
}
}
catch (Exception ex)
{
headerCollection.Add("ERROR", string.Format("An exception was thrown: {0}", ex.Message));
}
return headerCollection;
}
示例10: SendWithTemplate
public void SendWithTemplate()
{
QpidTemplate template = InitializeAndCreateTemplate();
IMessageProperties messageProperties = new MessageProperties();
//write all short props
messageProperties.ContentType = "text/plain";
messageProperties.ContentEncoding = "UTF-8";
messageProperties.CorrelationId = Encoding.UTF8.GetBytes("corr1");
messageProperties.DeliveryMode = MessageDeliveryMode.PERSISTENT;
messageProperties.Priority = 0;
for (int i = 0; i < 10; i++)
{
template.Send("amq.direct", "routing_key", delegate
{
Message msg = new Message(Encoding.UTF8.GetBytes("Message " + i), messageProperties);
Console.WriteLine("sending...");
return msg;
});
}
template.Send("amq.direct", "routing_key", delegate
{
Message msg = new Message(Encoding.UTF8.GetBytes("That's all, folks!"), messageProperties);
Console.WriteLine("sending...");
return msg;
});
}
示例11: AppendTo
public void AppendTo( MessageProperties messageProperties )
{
messageProperties.Type = messageType;
if( alternativeTypes.Any() )
messageProperties.Headers[ AlternativeMessageTypesHeaderKey ] = string.Join( AlternativeMessageTypeSeparator, alternativeTypes );
}
示例12: SetUp
public void SetUp()
{
postAckCallbackWasRun = false;
//var logger = new ConsoleLogger();
var logger = MockRepository.GenerateStub<IEasyNetQLogger>();
var consumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();
handlerRunner = new HandlerRunner(logger, consumerErrorStrategy);
Func<byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
Task.Factory.StartNew(() =>
{
deliveredBody = body;
deliveredProperties = properties;
deliveredInfo = info;
});
var consumer = MockRepository.GenerateStub<IBasicConsumer>();
channel = MockRepository.GenerateStub<IModel>();
consumer.Stub(x => x.Model).Return(channel).Repeat.Any();
var context = new ConsumerExecutionContext(
userHandler, messageInfo, messageProperties, messageBody, consumer);
context.SetPostAckCallback(() => postAckCallbackWasRun = true);
var autoResetEvent = new AutoResetEvent(false);
((HandlerRunner) handlerRunner).SynchronisationAction = () => autoResetEvent.Set();
handlerRunner.InvokeUserMessageHandler(context);
autoResetEvent.WaitOne(1000);
}
示例13: WriteSomeFiles
public void WriteSomeFiles()
{
var directory = new DirectoryInfo(tempDirectory);
foreach (var file in directory.EnumerateFiles())
{
file.Delete();
}
var properties = new MessageProperties();
var info = Helper.CreateMessageRecievedInfo();
var writer = new FileMessageWriter();
var messages = new List<HosepipeMessage>
{
new HosepipeMessage("This is message one", properties, info),
new HosepipeMessage("This is message two", properties, info),
new HosepipeMessage("This is message three", properties, info)
};
var parameters = new QueueParameters
{
QueueName = "Queue EasyNetQ_Tests_TestAsyncRequestMessage:EasyNetQ_Tests_Messages",
MessageFilePath = tempDirectory
};
writer.Write(messages, parameters);
foreach (var file in directory.EnumerateFiles())
{
Console.Out.WriteLine("{0}", file.Name);
}
}
示例14: SetUp
public void SetUp()
{
//var logger = new ConsoleLogger();
var logger = MockRepository.GenerateStub<IEasyNetQLogger>();
var consumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();
var eventBus = new EventBus();
handlerRunner = new HandlerRunner(logger, consumerErrorStrategy, eventBus);
Func<byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
Task.Factory.StartNew(() =>
{
deliveredBody = body;
deliveredProperties = properties;
deliveredInfo = info;
});
var consumer = MockRepository.GenerateStub<IBasicConsumer>();
channel = MockRepository.GenerateStub<IModel>();
consumer.Stub(x => x.Model).Return(channel).Repeat.Any();
var context = new ConsumerExecutionContext(
userHandler, messageInfo, messageProperties, messageBody, consumer);
var autoResetEvent = new AutoResetEvent(false);
eventBus.Subscribe<AckEvent>(x => autoResetEvent.Set());
handlerRunner.InvokeUserMessageHandler(context);
autoResetEvent.WaitOne(1000);
}
示例15: AddOrReplaceInMessageProperties
public void AddOrReplaceInMessageProperties(MessageProperties properties)
{
if (properties == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("properties");
}
properties["ContextMessageProperty"] = this;
}