Esempio n. 1
1
        public AmazonConnection(TypeOfMsg requestMsgType)
        {
            pollingMsg = requestMsgType;

            objClient = new AmazonSQSClient(AccessKeyId, SecretAccessKey);

            CreateQueueResponse queueResponse = new CreateQueueResponse();

            //Request existing queues
            ListQueuesResult allQueues = requestListOfQueuesInSQS();

            bool eventSparkzQueueListExists = false;

            foreach (string queueURL in allQueues.QueueUrl)
            {
                if (queueURL.Equals(QueueURLString))
                {
                    eventSparkzQueueListExists = true;
                }
            }

            if (!eventSparkzQueueListExists)
            {
                queueResponse = objClient.CreateQueue(new CreateQueueRequest()
                {
                    QueueName
                        = EventSparkzQueueName
                });
            }
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, CreateQueueResponse response)
        {
            
            int originalDepth = context.CurrentDepth;
            int targetDepth = originalDepth + 1;
            
            if (context.IsStartOfDocument) 
               targetDepth += 2;
            
            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {

                    if (context.TestExpression("QueueUrl", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.QueueUrl = unmarshaller.Unmarshall(context);
                        continue;
                    }
                } 
           }

            return;
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>  
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            CreateQueueResponse response = new CreateQueueResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;
            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {                    
                    if(context.TestExpression("CreateQueueResult", 2))
                    {
                        UnmarshallResult(context, response);                        
                        continue;
                    }
                    
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return response;
        }
Esempio n. 4
0
        /// <summary>
        /// CreateSubmitQueue:  IAM Account on consumer must have permission/policy to Receive and Delete
        ///    messages from this queue.
        ///
        /// </summary>
        /// <param name="queueName"></param>
        /// <returns></returns>
        private string CreateSubmitQueue(string queueName)
        {
            Debug.WriteLine("Queuename: " + queueName);
            var msg1 = new Amazon.SQS.Model.CreateQueueRequest()
                       .WithQueueName(queueName)
                       .WithDefaultVisibilityTimeout(60)
                       .WithDelaySeconds(20);

            Amazon.SQS.Model.CreateQueueResponse rsp = queue.CreateQueue(msg1);
            if (rsp.CreateQueueResult.IsSetQueueUrl())
            {
                return(rsp.CreateQueueResult.QueueUrl);
            }
            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// CreateQueueTopicPolicy:  Create Request Queue that subscribes to Topic,
        /// add permission/policy so topic can publish to the Queue
        /// </summary>
        /// <param name="queueName"></param>
        /// <returns></returns>
        private string CreateQueueTopicPolicy(string queueName)
        {
            Debug.WriteLine("Queuename: " + queueName);
            var msg1 = new Amazon.SQS.Model.CreateQueueRequest()
                       .WithQueueName(queueName)
                       .WithDefaultVisibilityTimeout(60)
                       .WithDelaySeconds(20);

            Amazon.SQS.Model.CreateQueueResponse rsp = queue.CreateQueue(msg1);
            if (rsp.CreateQueueResult.IsSetQueueUrl())
            {
                var attr = queue.GetQueueAttributes(new Amazon.SQS.Model.GetQueueAttributesRequest()
                                                    .WithQueueUrl(rsp.CreateQueueResult.QueueUrl)
                                                    .WithAttributeName(new string[] { "QueueArn" }));

                if (attr.IsSetGetQueueAttributesResult() && attr.GetQueueAttributesResult.IsSetAttribute())
                {
                    var policy = new Policy("QueuePolicy" + queueName);
                    policy.WithStatements(new Statement(Statement.StatementEffect.Allow)
                                          .WithPrincipals(new Principal("*"))
                                          .WithActionIdentifiers(Amazon.Auth.AccessControlPolicy.ActionIdentifiers.SQSActionIdentifiers.SendMessage)
                                          .WithResources(new Resource(attr.GetQueueAttributesResult.QueueARN))
                                          .WithConditions(Amazon.Auth.AccessControlPolicy.ConditionFactory.NewSourceArnCondition(topicArn)));

                    var setAttrsRequest = new Amazon.SQS.Model.SetQueueAttributesRequest()
                                          .WithQueueUrl(rsp.CreateQueueResult.QueueUrl);
                    setAttrsRequest.Attribute.Add(new Amazon.SQS.Model.Attribute()
                                                  .WithName("Policy")
                                                  .WithValue(policy.ToJson()));

                    var setAttrsResponse = queue.SetQueueAttributes(setAttrsRequest);
                }

                return(rsp.CreateQueueResult.QueueUrl);
            }
            return(null);
        }