public void SetUp() { _client = AWSClientFactory.CreateAmazonSQSClient(Access_Key_ID, Secret_Access_Key); //Ensure we create a test queue for the test cases. And remember to delete it in the teardown method. bool hasCallbackArrived = false; SQSResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; _client.CreateQueue(new CreateQueueRequest { QueueName = _queue_UnitTesting, DefaultVisibilityTimeout = 3 }); EnqueueConditional(() => hasCallbackArrived); EnqueueTestComplete(); }
private void btnCreateQueue_Click(object sender, RoutedEventArgs e) { CreateQueueRequest sqsRequest = new CreateQueueRequest(); if (!string.IsNullOrEmpty(QueueNameTextBox.Text)) { Regex rg = new Regex(_specialCharacters); if (rg.IsMatch(this.QueueName.Trim())) { this.Dispatcher.BeginInvoke(() => { this.QueueUrl = "Error:\nA Queue name cannot have special characters."; } ); return; } sqsRequest.QueueName = this.QueueName.Trim(); this.Dispatcher.BeginInvoke(() => { this.QueueUrl = "Please wait..."; }); sqs.OnSQSResponse += GetCreateQueueResponse; sqs.CreateQueue(sqsRequest); } }
private void Create_queue() { var createQueueResponse = _sqs.CreateQueue(new CreateQueueRequest { QueueName = _queueName }); _queueUrl = createQueueResponse.CreateQueueResult.QueueUrl; }
static void Main(string[] args) { Console.Title = "CloudServiceBus: Client"; AmazonSQS sqs = AwsFacade.GetSqsClient(); var requestQueueUrl = ConfigurationManager.AppSettings["QueueUrl"]; //create a queue for responses: var queueName = Guid.NewGuid().ToString(); var createQueueRequest = new CreateQueueRequest(); createQueueRequest.QueueName = queueName; var createQueueResponse = sqs.CreateQueue(createQueueRequest); var responseQueueUrl = createQueueResponse.CreateQueueResult.QueueUrl; var listener = new MessageListener(); ThreadPool.QueueUserWorkItem(new WaitCallback(listener.StartListening), responseQueueUrl); Console.WriteLine("*"); Console.WriteLine("Sending messages on URL: {0}", requestQueueUrl); Console.WriteLine("Receiving responses on URL: {0}", responseQueueUrl); Console.WriteLine("*"); var messageBody = Console.ReadLine(); while (messageBody != "x") { var parts = messageBody.Split(' '); if (parts[0] == "get") { var duration = int.Parse(parts[1]); var serviceRequest = new GetChangedEmployeesRequest(); serviceRequest.LastChangeDate = DateTime.Now.AddDays(duration).Date; serviceRequest.ResponseQueueUrl = responseQueueUrl; var request = new SendMessageRequest(); request.QueueUrl = requestQueueUrl; request.RequestToBody(serviceRequest); SendMessage(request, sqs, serviceRequest); } if (parts[0] == "flush") { var serviceRequest = new FlushDataStoreRequest(); serviceRequest.StoreIdentifier = "Sixeyed-CloudServiceBus-ResponseData"; var request = new SendMessageRequest(); request.QueueUrl = requestQueueUrl; request.RequestToBody(serviceRequest); SendMessage(request, sqs, serviceRequest); } messageBody = Console.ReadLine(); } }
/// <summary> /// Creates a new queue in Amazon SQS and grants SendMessage only access to MessageGears. /// </summary> /// <param name="queueName"> /// The name of the queue to be created. /// </param> /// <returns> /// The full url of the newly created queue. /// </returns> public String CreateQueue(String queueName) { CreateQueueRequest request = new CreateQueueRequest() .WithQueueName(queueName) .WithDefaultVisibilityTimeout(properties.SQSVisibilityTimeoutSecs); CreateQueueResponse response = sqs.CreateQueue(request); addQueuePermission(response.CreateQueueResult.QueueUrl); setMaximumMessageSize(response.CreateQueueResult.QueueUrl); log.Info("Create queue successful: " + queueName); return(response.CreateQueueResult.QueueUrl); }
/// <summary> /// </summary> /// <param name="name"></param> /// <param name="visibilitySeconds"></param> /// <param name="delaySeconds"></param> /// <returns></returns> internal Queue CreateQueue(string name, int visibilitySeconds = 30, int delaySeconds = 0) { var request = new CreateQueueRequest { QueueName = name, DefaultVisibilityTimeout = Convert.ToDecimal(visibilitySeconds), DelaySeconds = delaySeconds }; CreateQueueResponse response = _sqsClient.CreateQueue(request); return(response.CreateQueueResult.IsSetQueueUrl() ? new Queue { Name = name, Url = response.CreateQueueResult.QueueUrl } : null); }
private string TheQueueUrlFrom(ListQueuesResponse listQueuesResponse) { string queueUrl; if (listQueuesResponse.ListQueuesResult.QueueUrl.Count == 0) { var response = _client.CreateQueue(new CreateQueueRequest { QueueName = _config.SqsQueueName }); queueUrl = response.CreateQueueResult.QueueUrl; } else { queueUrl = listQueuesResponse.ListQueuesResult.QueueUrl[0]; } return(queueUrl); }
protected override bool Execute(AmazonSQS client) { Logger.LogMessage(MessageImportance.Normal, "Creating SQS Queue {0}", QueueName); var request = new CreateQueueRequest { QueueName = QueueName }; CreateQueueResponse response = client.CreateQueue(request); if (response.IsSetCreateQueueResult()) { QueueUrl = response.CreateQueueResult.QueueUrl; Logger.LogMessage(MessageImportance.Normal, "Creates SQS Queue {0} at {1}", QueueName, QueueUrl); return true; } Logger.LogMessage(MessageImportance.Normal, "Failed to create SQS Queue {0}", QueueName); return false; }
public CreateSQSQueueResponse Invoke(CreateSQSQueueRequest request) { Trace("Starting..."); Trace("...Attempting to create queue:={0}", request.QueueName); var response = _amazonSQS.CreateQueue(new CreateQueueRequest { DefaultVisibilityTimeout = _configuration.QueueVisibilityTimeoutSeconds, QueueName = request.QueueName, }); Trace("Completed, queue '{0}' created", response.CreateQueueResult.QueueUrl); return(new CreateSQSQueueResponse { Status = CreateSQSCommandStatus.Ok }); }
/// <summary> /// /// The CreateQueue action creates a new queue. You must provide a queue name that is unique within the scope of the queues you own. The queue is assigned a queue URL; you must use this URL when performing actions on the queue. When you create a queue, if a queue with the same name already exists, CreateQueue returns the queue URL with an error indicating that the queue already exists. /// /// </summary> /// <param name="service">Instance of AmazonSQS service</param> /// <param name="request">CreateQueueRequest request</param> public static void InvokeCreateQueue(AmazonSQS service, CreateQueueRequest request) { try { CreateQueueResponse response = service.CreateQueue(request); Console.WriteLine ("Service Response"); Console.WriteLine ("============================================================================="); Console.WriteLine (); Console.WriteLine(" CreateQueueResponse"); if (response.IsSetCreateQueueResult()) { Console.WriteLine(" CreateQueueResult"); CreateQueueResult createQueueResult = response.CreateQueueResult; if (createQueueResult.IsSetQueueUrl()) { Console.WriteLine(" QueueUrl"); Console.WriteLine(" {0}", createQueueResult.QueueUrl); } } if (response.IsSetResponseMetadata()) { Console.WriteLine(" ResponseMetadata"); ResponseMetadata responseMetadata = response.ResponseMetadata; if (responseMetadata.IsSetRequestId()) { Console.WriteLine(" RequestId"); Console.WriteLine(" {0}", responseMetadata.RequestId); } } } 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); } }
static void SetupTopicAndQueue() { snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USEast1); sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USEast1); long ticks = DateTime.Now.Ticks; topicArn = snsClient.CreateTopic(new CreateTopicRequest { Name = "GlacierDownload-" + ticks }).CreateTopicResult.TopicArn; queueUrl = sqsClient.CreateQueue(new CreateQueueRequest() { QueueName = "GlacierDownload-" + ticks }).CreateQueueResult.QueueUrl; queueArn = sqsClient.GetQueueAttributes(new GetQueueAttributesRequest() { QueueUrl = queueUrl, AttributeName = new List <string> { "QueueArn" } }).GetQueueAttributesResult.QueueARN; snsClient.Subscribe(new SubscribeRequest() { Protocol = "sqs", Endpoint = queueArn, TopicArn = topicArn }); // Add policy to the queue so SNS can send messages to the queue. var policy = SQS_POLICY.Replace("{QuernArn}", queueArn).Replace("{TopicArn}", topicArn); sqsClient.SetQueueAttributes(new SetQueueAttributesRequest() { QueueUrl = queueUrl, Attribute = new List <Amazon.SQS.Model.Attribute>() { new Amazon.SQS.Model.Attribute() { Name = "Policy", Value = policy } } }); }
protected override bool Execute(AmazonSQS client) { Logger.LogMessage(MessageImportance.Normal, "Creating SQS Queue {0}", QueueName); var request = new CreateQueueRequest { QueueName = QueueName }; CreateQueueResponse response = client.CreateQueue(request); if (response.IsSetCreateQueueResult()) { QueueUrl = response.CreateQueueResult.QueueUrl; Logger.LogMessage(MessageImportance.Normal, "Creates SQS Queue {0} at {1}", QueueName, QueueUrl); return(true); } Logger.LogMessage(MessageImportance.Normal, "Failed to create SQS Queue {0}", QueueName); return(false); }
private static void EnsureQueue() { if (!string.IsNullOrEmpty(queueUrl)) { return; } EnsureSqs(); lock (lockObject) { CreateQueueRequest sqsRequest = new CreateQueueRequest(); sqsRequest.QueueName = ConfigurationManager.AppSettings["awssqsqueue"]; if (sqsRequest.QueueName == null) { Logger.Info(string.Format("awssqsqueue not configured, configure it first!")); return; } CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest); queueUrl = createQueueResponse.CreateQueueResult.QueueUrl; } }
public CraneChatRequestSender() { // initialize Amazon SQSClient AmazonSQSConfig sqsConfig = new AmazonSQSConfig(); sqsConfig.ServiceURL = ConfigurationManager.AppSettings["SQSServiceURL"].ToString(); m_sqsClient = AWSClientFactory.CreateAmazonSQSClient(sqsConfig); // create 'Request' queue and save its URL if (null != m_sqsClient) { try { CreateQueueRequest createQueueRequest = new CreateQueueRequest().WithQueueName("Request"); CreateQueueResponse createQueueResponse = m_sqsClient.CreateQueue(createQueueRequest); m_requestQueueUrl = createQueueResponse.CreateQueueResult.QueueUrl; } catch (AmazonSQSException /*sqsException*/) { throw; } } }
public void Test_B_CreateQueue_And_Check_For_Valid_Response() { bool hasCallbackArrived = false; bool actualValue = false; bool expectedValue = true; SQSResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; CreateQueueResponse response = result as CreateQueueResponse; if (null != response) { CreateQueueResult createResult = response.CreateQueueResult; if (null != createResult) { actualValue = true; } } hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; //Create request object. _client.CreateQueue(new CreateQueueRequest { QueueName = _queue_UnitTesting_1 }); EnqueueConditional(() => hasCallbackArrived); EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue)); EnqueueTestComplete(); }
public void SetUp() { _client = AWSClientFactory.CreateAmazonSQSClient(Access_Key_ID, Secret_Access_Key); //Ensure we create a test queue for the test cases. And remember to delete it in the teardown method. bool hasCallbackArrived = false; SQSResponseEventHandler<object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { ISQSResponse result = args.Response; //Unhook from event. _client.OnSQSResponse -= handler; hasCallbackArrived = true; }; //Hook to event _client.OnSQSResponse += handler; _client.CreateQueue(new CreateQueueRequest { QueueName = _queue_UnitTesting, DefaultVisibilityTimeout = 3 }); EnqueueConditional(() => hasCallbackArrived); EnqueueTestComplete(); }
public static void Main(string[] args) { const string QUEUENAME = "MyQueue"; AmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient(); try { Console.WriteLine("==========================================="); Console.WriteLine("Getting Started with Amazon SQS"); Console.WriteLine("===========================================\n"); //Creating a queue Console.WriteLine("Create a queue called MyQueue.\n"); CreateQueueRequest sqsRequest = new CreateQueueRequest(); sqsRequest.QueueName = QUEUENAME; CreateQueueResponse createQueueResponse = sqs.CreateQueue(sqsRequest); String myQueueUrl; myQueueUrl = createQueueResponse.CreateQueueResult.QueueUrl; //Confirming the queue exists ListQueuesRequest listQueuesRequest = new ListQueuesRequest(); ListQueuesResponse listQueuesResponse = sqs.ListQueues(listQueuesRequest); var getQueueReq = new GetQueueUrlRequest(); getQueueReq.QueueName = "AppZwitschern"; var getQueueResp = sqs.GetQueueUrl(getQueueReq); Console.WriteLine(":: Url={0}", getQueueResp.GetQueueUrlResult.QueueUrl); Console.WriteLine("Printing list of Amazon SQS queues.\n"); if (listQueuesResponse.IsSetListQueuesResult()) { ListQueuesResult listQueuesResult = listQueuesResponse.ListQueuesResult; foreach (String queueUrl in listQueuesResult.QueueUrl) { Console.WriteLine(" QueueUrl: {0}", queueUrl); } } Console.WriteLine(); //Sending a message Console.WriteLine("Sending a message to MyQueue.\n"); SendMessageRequest sendMessageRequest = new SendMessageRequest(); sendMessageRequest.QueueUrl = myQueueUrl; //URL from initial queue creation sendMessageRequest.MessageBody = "This is my message text."; sqs.SendMessage(sendMessageRequest); //Receiving a message ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(); receiveMessageRequest.QueueUrl = myQueueUrl; ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest); if (receiveMessageResponse.IsSetReceiveMessageResult()) { Console.WriteLine("Printing received message.\n"); ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult; foreach (Message message in receiveMessageResult.Message) { 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()) { Console.WriteLine(" Body: {0}", message.Body); } foreach (Amazon.SQS.Model.Attribute attribute in message.Attribute) { Console.WriteLine(" Attribute"); if (attribute.IsSetName()) { Console.WriteLine(" Name: {0}", attribute.Name); } if (attribute.IsSetValue()) { Console.WriteLine(" Value: {0}", attribute.Value); } } } } String messageRecieptHandle = receiveMessageResponse.ReceiveMessageResult.Message[0].ReceiptHandle; //Deleting a message Console.WriteLine("Deleting the message.\n"); DeleteMessageRequest deleteRequest = new DeleteMessageRequest(); deleteRequest.QueueUrl = myQueueUrl; deleteRequest.ReceiptHandle = messageRecieptHandle; sqs.DeleteMessage(deleteRequest); } 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); } Console.WriteLine("Press Enter to continue..."); Console.Read(); }
// public string GetInventory() // { // AmazonGlacier client; // try // { // using (client = new AmazonGlacierClient(RegionEndpoint)) // { // // Setup SNS topic and SQS queue. // SetupTopicAndQueue(); // GetInventory(); // } // Console.WriteLine("Operations successful. To continue, press Enter"); // } // catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } // catch (AmazonServiceException e) { Console.WriteLine(e.Message); } // catch (Exception e) { Console.WriteLine(e.Message); } // finally // { // // Delete SNS topic and SQS queue. // _snsClient.DeleteTopic(new DeleteTopicRequest() { TopicArn = _topicArn }); // sqsClient.DeleteQueue(new DeleteQueueRequest() { QueueUrl = _queueUrl }); // } // } static void SetupTopicAndQueue() { _snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.USEast1); sqsClient = new AmazonSQSClient(Amazon.RegionEndpoint.USEast1); var ticks = DateTime.Now.Ticks; _topicArn = _snsClient.CreateTopic(new CreateTopicRequest { Name = "GlacierDownload-" + ticks }).CreateTopicResult.TopicArn; _queueUrl = sqsClient.CreateQueue(new CreateQueueRequest() { QueueName = "GlacierDownload-" + ticks }).CreateQueueResult.QueueUrl; _queueArn = sqsClient.GetQueueAttributes(new GetQueueAttributesRequest() { QueueUrl = _queueUrl, AttributeName = new List<string> { "QueueArn" } }).GetQueueAttributesResult.QueueARN; _snsClient.Subscribe(new SubscribeRequest() { Protocol = "sqs", Endpoint = _queueArn, TopicArn = _topicArn }); // Add policy to the queue so SNS can send messages to the queue. var policy = SQS_POLICY.Replace("{QuernArn}", _queueArn).Replace("{TopicArn}", _topicArn); sqsClient.SetQueueAttributes(new SetQueueAttributesRequest() { QueueUrl = _queueUrl, Attribute = new List<Amazon.SQS.Model.Attribute>() { new Amazon.SQS.Model.Attribute() { Name = "Policy", Value = policy } } }); }