本文整理汇总了C#中Amazon.SQS.Model.ReceiveMessageRequest类的典型用法代码示例。如果您正苦于以下问题:C# ReceiveMessageRequest类的具体用法?C# ReceiveMessageRequest怎么用?C# ReceiveMessageRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReceiveMessageRequest类属于Amazon.SQS.Model命名空间,在下文中一共展示了ReceiveMessageRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get_Msg_From_Req_Q
public static bool Get_Msg_From_Req_Q(out Amazon.SQS.Model.Message msg, out bool msgFound)
{
msgFound = false;
msg = null;
try
{
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
receiveMessageRequest.MaxNumberOfMessages = 1;
receiveMessageRequest.QueueUrl = requests_Q_url;
ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
if (receiveMessageResponse.IsSetReceiveMessageResult())
{
ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
List<Amazon.SQS.Model.Message> receivedMsges = receiveMessageResponse.ReceiveMessageResult.Message;
if (receivedMsges.Count == 0)
{
return true;
}
msgFound = true;
msg = receivedMsges[0];
}
}
catch (AmazonSQSException ex)
{
Console.WriteLine("Caught Exception: " + ex.Message);
Console.WriteLine("Response Status Code: " + ex.StatusCode);
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Error Type: " + ex.ErrorType);
Console.WriteLine("Request ID: " + ex.RequestId);
Console.WriteLine("XML: " + ex.XML);
return false;
}
return true;
}
示例2: ReceiveMessage
private void ReceiveMessage()
{
var receiveMessageRequest = new ReceiveMessageRequest();
receiveMessageRequest.QueueUrl = _handler.QueueUrl;
var receiveMessageResponse = _sqsClient.ReceiveMessage(receiveMessageRequest);
if (receiveMessageResponse.IsSetReceiveMessageResult() && receiveMessageResponse.ReceiveMessageResult.Message.Count > 0)
{
Console.WriteLine("Received message");
var receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
foreach (Message message in receiveMessageResult.Message)
{
Console.WriteLine("Message body: {0}", message.Body);
foreach (var handler in Container.GetAll<IServiceHandler>())
{
//TODO - need to refactor this, multiple handlers means multiple deserialization
if (handler.QueueName == _handler.QueueName && handler.IsRequestHandled(message))
{
Console.WriteLine("Passing request to handler: {0}", handler.GetType().Name);
handler.HandleRequest(message);
}
}
}
Console.WriteLine("Deleting message");
var messageRecieptHandle = receiveMessageResponse.ReceiveMessageResult.Message[0].ReceiptHandle;
var deleteRequest = new DeleteMessageRequest()
.WithQueueUrl(_handler.QueueUrl)
.WithReceiptHandle(messageRecieptHandle);
_sqsClient.DeleteMessage(deleteRequest);
}
}
示例3: GetMessage
public async Task<Amazon.SQS.Model.Message> GetMessage(string queueName, int timeoutInMilliseconds, int numberOfCacheableMessages)
{
Amazon.SQS.Model.Message message = null;
if (_queue.ContainsKey(queueName) && _queue[queueName].TryDequeue(out message)) return message;
var request = new ReceiveMessageRequest(queueName)
{
MaxNumberOfMessages = numberOfCacheableMessages,
WaitTimeSeconds = (int)TimeSpan.FromMilliseconds(timeoutInMilliseconds).TotalSeconds
};
using (var client = new AmazonSQSClient(_credentials))
{
var response = await client.ReceiveMessageAsync(request);
if (response.HttpStatusCode != HttpStatusCode.OK) return message;
if (response.ContentLength == 0) return message;
if (!response.Messages.Any()) return message;
AddToQueue(queueName, response.Messages);
if(_queue.ContainsKey(queueName))
_queue[queueName].TryDequeue(out message);
}
return message;
}
示例4: readNextMessage
/// <summary>
/// Poll messages from the queue. Given the download process takes many hours there is extra
/// long retry logic.
/// </summary>
/// <returns>The next message in the queue;</returns>
Message readNextMessage()
{
int retryAttempts = 0;
var receiveRequest = new ReceiveMessageRequest() { QueueUrl = this.queueUrl, MaxNumberOfMessages = 1 };
while (true)
{
try
{
var receiveResponse = this.sqsClient.ReceiveMessage(receiveRequest);
retryAttempts = 0;
if (receiveResponse.Messages.Count == 0)
{
Thread.Sleep((int)(this.options.PollingInterval * 1000 * 60));
continue;
}
return receiveResponse.Messages[0];
}
catch (Exception)
{
retryAttempts++;
if (retryAttempts <= MAX_OPERATION_RETRY)
Thread.Sleep(60 * 1000);
else
throw;
}
}
}
示例5: readNextMessageAsync
/// <summary>
/// Poll messages from the queue. Given the download process takes many hours there is extra
/// long retry logic.
/// </summary>
/// <returns>The next message in the queue;</returns>
async Task<Message> readNextMessageAsync()
{
int retryAttempts = 0;
var receiveRequest = new ReceiveMessageRequest() { QueueUrl = this.queueUrl, MaxNumberOfMessages = 1 };
while (true)
{
try
{
var receiveResponse = await this.sqsClient.ReceiveMessageAsync(receiveRequest).ConfigureAwait(false);
retryAttempts = 0;
if (receiveResponse.Messages.Count == 0)
{
await Task.Delay((int)(this.options.PollingInterval * 1000 * 60)).ConfigureAwait(false);
continue;
}
return receiveResponse.Messages[0];
}
catch (Exception)
{
retryAttempts++;
if (retryAttempts <= MAX_OPERATION_RETRY)
Task.Delay(1000 * 60).Wait();
else
throw;
}
}
}
示例6: Next
public IMessage Next(int timeout)
{
try
{
var request = new ReceiveMessageRequest()
{
MaxNumberOfMessages = 1,
QueueName = Name,
VisibilityTimeout = timeout
};
var response = _client.ReceiveMessage(request);
var message = response.ReceiveMessageResult.Message.SingleOrDefault();
if (message == null)
return null;
return new AmazonMessage { Content = message.Body, Message = message };
}
catch (AmazonSQSException e)
{
throw new MessageQueueException(string.Format("Failed to get next message for '{0}'.", Name), e);
}
}
示例7: GetNextMessage
public AlertMessage GetNextMessage()
{
//Receiving a message
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
receiveMessageRequest.QueueUrl = queueUrl;
ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
if (receiveMessageResponse.IsSetReceiveMessageResult())
{
Console.WriteLine("Printing received message.\n");
ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
foreach (Message message in receiveMessageResult.Message)
{
AlertMessage m = new AlertMessage();
Console.WriteLine(" Message");
if (message.IsSetMessageId())
{
Console.WriteLine(" MessageId: {0}", message.MessageId);
}
if (message.IsSetReceiptHandle())
{
Console.WriteLine(" ReceiptHandle: {0}", message.ReceiptHandle);
}
if (message.IsSetMD5OfBody())
{
Console.WriteLine(" MD5OfBody: {0}", message.MD5OfBody);
}
if (message.IsSetBody())
{
m.Body = message.Body;
Console.WriteLine(" Body: {0}", message.Body);
}
foreach (Amazon.SQS.Model.Attribute attribute in message.Attribute)
{
Console.WriteLine(" Attribute");
if (attribute.IsSetName() && attribute.Name == "Subject")
{
if (attribute.IsSetValue())
{
m.Subject = attribute.Value;
}
}
if (attribute.IsSetValue())
{
Console.WriteLine(" Value: {0}", attribute.Value);
}
}
// Deleting a message
Console.WriteLine("Deleting the message.\n");
DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
deleteRequest.QueueUrl = queueUrl;
deleteRequest.ReceiptHandle = message.ReceiptHandle;
sqs.DeleteMessage(deleteRequest);
return m;
}
}
return null;
}
示例8: GetRequests
public virtual List<CombinedMarketDataRequest> GetRequests()
{
var client = this.GetClient();
var queueReceiveRequest = new ReceiveMessageRequest
{
MaxNumberOfMessages = 10,
};
var response = client.ReceiveMessage(queueReceiveRequest);
return Convert(response);
}
示例9: Receive
public Message Receive(ReceiveMessageRequest request)
{
if (request == null)
return null;
request.MaxNumberOfMessages = 1;
var response = SqsClient.ReceiveMessage(request);
return response == null
? null
: response.Messages.SingleOrDefault();
}
示例10: Main
static void Main(string[] args)
{
// AWS: Get instance public address
string myId = "localhost";
try
{
myId = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
}
catch
{
}
// AWS SQS Client
var sqsClient = new AmazonSQSClient();
while (true)
{
// Get the next message
ReceiveMessageRequest request = new ReceiveMessageRequest()
.WithQueueUrl("https://queue.amazonaws.com/*****/codeCampDemo")
.WithMaxNumberOfMessages(1);
var response = sqsClient.ReceiveMessage(request);
foreach (var retrievedMessage in response.ReceiveMessageResult.Message)
{
var messageJson = JsonValue.Parse(retrievedMessage.Body);
var message = messageJson["message"].ReadAs<string>();
Console.WriteLine(message);
message = "Echo: " + message;
string address = string.Format("http://{0}", messageJson["sender"].ReadAs<string>());
var connection = new HubConnection(address);
connection.Start().Wait();
IHubProxy pongHub = connection.CreateProxy("MvcWebRole1.Hubs.EchoHub");
pongHub.Invoke("DoUpdateMessage", message, myId).Wait();
//Process the message and then delete the message
DeleteMessageRequest deleteRequest = new DeleteMessageRequest()
.WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
.WithReceiptHandle(retrievedMessage.ReceiptHandle);
sqsClient.DeleteMessage(deleteRequest);
}
Thread.Sleep(1000);
}
}
示例11: MessageGearsAwsQueuePoller
/// <summary>
/// Instantiates the Poller.
/// </summary>
/// <param name="props">
/// A <see cref="MessageGearsProperties"/>
/// </param>
/// <param name="listener">
/// A <see cref="MessageGearsListener"/>
/// </param>
/// <param name="myAwsAccountKey">
/// You AWS Account Key
/// </param>
/// <param name="myAwsSecretKey">
/// Your AWS Secret Key
/// </param>
public MessageGearsAwsQueuePoller(MessageGearsAwsProperties props, MessageGearsListener listener)
{
this.props = props;
this.emptyQueueDelayMillis = props.EmptyQueuePollingDelaySecs * 1000;
this.listener = listener;
AmazonSQSConfig config = new AmazonSQSConfig().WithMaxErrorRetry(props.SQSMaxErrorRetry);
this.sqs = AWSClientFactory.CreateAmazonSQSClient (props.MyAWSAccountKey, props.MyAWSSecretKey, config);
this.receiveMessageRequest = new ReceiveMessageRequest ()
.WithQueueUrl (props.MyAWSEventQueueUrl)
.WithMaxNumberOfMessages (props.SQSMaxBatchSize)
.WithAttributeName("ApproximateReceiveCount")
.WithVisibilityTimeout(props.SQSVisibilityTimeoutSecs);
this.deleteMessageRequest = new DeleteMessageRequest().WithQueueUrl(props.MyAWSEventQueueUrl);
}
示例12: ReadFromQueue
static void ReadFromQueue(AWSCredentials credentials)
{
AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);
string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";
ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl);
request.MaxNumberOfMessages = 1;
ReceiveMessageResponse response = client.ReceiveMessage(request);
foreach (var message in response.Messages)
{
// Do something with the message
}
}
示例13: Get
public static Message Get(string queue_url)
{
AmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient();
ReceiveMessageRequest r_msgreq = new ReceiveMessageRequest();
r_msgreq.MaxNumberOfMessages = 1;
r_msgreq.QueueUrl = queue_url;
Decimal Vis_Timeout = System.Convert.ToDecimal(ConfigurationManager.AppSettings["SQS_Visibility"]);
r_msgreq.VisibilityTimeout = Vis_Timeout;
ReceiveMessageResponse r_msgres = sqs.ReceiveMessage(r_msgreq);
//ChangeMessageVisibilityRequest chg_message_vis = new ChangeMessageVisibilityRequest();
//chg_message_vis.QueueUrl = ConfigurationManager.AppSettings["SQSUrl"];
//chg_message_vis.ReceiptHandle = r_msgres.ResponseMetadata.RequestId
ReceiveMessageResult r_msgrst = r_msgres.ReceiveMessageResult;
Message msg = r_msgrst.Message.FirstOrDefault();
return msg;
}
示例14: Receive
private static ReceivedMessage Receive()
{
var request = new ReceiveMessageRequest
{
QueueUrl = _awsConfig.QueueUrl,
MaxNumberOfMessages = 1
};
var response = _client.ReceiveMessage(request);
if (response.Messages.Count == 0) return null;
var message = response.Messages[0];
var json = message.Body;
return new ReceivedMessage
{
Email = JsonConvert.DeserializeObject<EmailMessage>(json),
ReceiptHandle = message.ReceiptHandle
};
}
示例15: ListTop10Messages
public List<QueueMessage> ListTop10Messages(string queueUrl)
{
var req = new ReceiveMessageRequest() {
MaxNumberOfMessages = 10,
QueueUrl = queueUrl
};
req.AttributeName.Add("SentTimestamp");
req.AttributeName.Add("ApproximateReceiveCount");
req.AttributeName.Add("ApproximateFirstReceiveTimestamp");
var result = new List<QueueMessage>(10);
var response = client.ReceiveMessage(req);
if (response.IsSetReceiveMessageResult() && response.ReceiveMessageResult.IsSetMessage()) {
DateTime epochDate = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc);
foreach (Message msg in response.ReceiveMessageResult.Message) {
var qm = new QueueMessage() {
Body = msg.Body,
ReceiptHandle = msg.ReceiptHandle
};
if (msg.IsSetAttribute()) {
foreach (Amazon.SQS.Model.Attribute att in msg.Attribute) {
switch (att.Name) {
case "SentTimestamp":
qm.Sent = epochDate.AddMilliseconds(double.Parse(att.Value));
break;
case "ApproximateReceiveCount":
qm.ApproximateReceiveCount = Int32.Parse(att.Value);
break;
case "ApproximateFirstReceiveTimestamp":
qm.FirstReceived = epochDate.AddMilliseconds(double.Parse(att.Value));
break;
}
}
}
result.Add(qm);
}
}
return result;
}