I'm attempting to send an SQS message to a FIFO queue. I've run into problems with the Message Group ID attribute. I thought using the MessageAttributeValue was the correct way to set up the "MessageGroupId", but AWS doesn't seem to recognize this input. What is the proper method for setting up SQS SendMessageRequest.MessageAttributes?
I've made a console project that sends a message. I've attempted a few things to set the Message Group Id attribute, but I get an exception when sending the message.
SendMessageRequest sendMessageRequest = new SendMessageRequest();
sendMessageRequest.QueueUrl = myURL;
MessageAttributeValue mavGroupID = new MessageAttributeValue();
mavGroupID.DataType = "MessageGroupId";
mavGroupID.StringValue = "1";
MessageAttributeValue mavDeDuplicateID = new MessageAttributeValue();
mavDeDuplicateID.DataType = "MessageDeduplicationId";
mavDeDuplicateID.StringValue = "1";
sendMessageRequest.MessageAttributes.Add("0", mavGroupID);
sendMessageRequest.MessageAttributes.Add("1", mavDeDuplicateID);
string sMyMessage = "";
Console.WriteLine();
Console.WriteLine("Message to send: ");
sMyMessage = Console.ReadLine();
sendMessageRequest.MessageBody = sMyMessage;
SendMessageResponse sMR = amazonSQSClient.SendMessage(sendMessageRequest);
Amazon.SQS.AmazonSQSException: 'The request must contain the parameter MessageGroupId.'
The MessageGroupId is specified on the SendMessageRequest itself. It is not a MessageAttribute.
SendMessageRequest.MessageGroupId = 'foo'
See: SendMessageRequest Class | AWS SDK for .NET V3
Related
I am trying to create and send an envelope on the demo environment using the docusign C# API. I am using JWT as my OAuth2 flow. I am able to properly grab the access code needed to authorized my embedded signing.
The function CreateEnvelope fails and throws an exception. The exception shows no information other than that the function failed.
Image of Exception
Has anyone encountered a similar situation before? I have provided a snippet of the code below. Is there anything clearly wrong with how I may be trying to create the envelope?
public static void DocusignFormatter()
{
EnvelopeDefinition envDef = new EnvelopeDefinition();
Document doc = new Document();
doc.DocumentBase64 = System.Convert.ToBase64String(pdfFileInfo.fileBytes);
doc.Name = pdfFileInfo.DocName;
doc.DocumentId = "1";
envDef.Documents = new List<Document>();
envDef.Documents.Add(doc);
envDef.Recipients = new Recipients();
envDef.Recipients.Signers = new List<Signer>();
for (int i = 0; i < signatureFields.Count; i++)
{
Signer signer = new Signer();
signer.Email = docRegistrant.Email;
signer.Name = docApplicants[i].FirstName + " " + docApplicants[i].LastName;
signer.RecipientId = $"{i+1}";
signer.Tabs = new Tabs();
signer.Tabs.SignHereTabs = new List<SignHere>();
List<MyPdfSignatureField> fields;
signatureFields.TryGetValue(i, out fields);
foreach (MyPdfSignatureField field in fields)
{
SignHere signHere = new SignHere();
signHere.DocumentId = "1";
signHere.PageNumber = field.PageNum.ToString();
signHere.RecipientId = i.ToString();
signHere.XPosition = field.XLocation.ToString();
signHere.YPosition = field.YLocation.ToString();
signer.Tabs.SignHereTabs.Add(signHere);
}
envDef.Recipients.Signers.Add(signer);
}
envDef.Status = "created";
ApiClient apiClient = new ApiClient(DocusignHelpers.OAuthBasePath);
Configuration cfi = new Configuration(apiClient);
cfi.AddDefaultHeader("Authorization", "Bearer " + DocusignHelpers.AccessToken);
cfi.AccessToken = DocusignHelpers.AccessToken;
cfi.Password = DocusignHelpers.Password;
EnvelopesApi envelopesApi = new EnvelopesApi(cfi);
EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(DocusignHelpers.AccountId, envDef);
Caught Exception values
you are missing this line:
envDef.EmailSubject = "Test, please sign.";
But that's not the reason for the exception, since you created it as "created" (draft) mode, but it would be the issue once you try to send it.
You may want to confirm the values of all your recipients and ensure you're not sending something that's not an email (for example) in an email field etc.
I solved this friends.
My api url was incorrect.
My key confusion was that the auth endpoints have a separate base url than the rest of the RESTful API.
Authorization url for the demo was: https://account-d.docusign.com
The API client object actually has static fields that contain the urls for the different platforms demo, prod, staging.
I ended up using
ApiClient.Demo_REST_BasePath = "https://demo.docusign.net/restapi"
Thank you all for the replies and help
I have the following code in C#, which does not throw error if the routing key is invalid.
var connFactory = GetConnectionFactory();
using (var conn = connFactory.CreateConnection())
{
using (var channel = conn.CreateModel())
{
channel.TxSelect();
var publicationAddress = new PublicationAddress(ExchangeType.Direct, Settings.ServiceBusExchange, Settings.ServiceBusRoutingKey);
var headers = new Dictionary<String, Object>();
headers.Add("TransactionID", transactionID);
var basicProperties = new BasicProperties();
basicProperties.ContentEncoding = Encoding.UTF8.ToString();
basicProperties.ContentType = "text/xml";
basicProperties.Headers = headers;
basicProperties.DeliveryMode = 2;
var payLoad = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(publicationAddress, basicProperties, payLoad);
channel.TxCommit();
}
}
My question is, how can I make the code throw error if the routing key is invalid? Like when I Publish a message using RabbitMQ UI with invalid routing key, it gives a message "Message published, but not routed."
Thanks in advance.
it does not exist the concept of "invalid routing key", since you can bind dynamically queues to the exchanges.
Btw what you are looking for is "unroutable messages", you have to use the mandatory flag and implement the ReturnListener in the same channel, if a message does not reach any queue will be redirect to the handler.
In this in this way (the code is Java, but in c# is more or less the same):
boolean isMandatory = true; // if true the message will be handled by HandlingReturnListener
// if false the message will be dropped!
channel.addReturnListener(new ReturnListener() {
public void handleReturn(int replyCode, String replyText, String exchange, String routingKey, AMQP.BasicProperties properties, byte[] body) throws IOException {
System.out.println(replyText + ":" + replyCode);
System.out.println("******** UnHandled Message ***************");
}
});
String myExchange = "myUnroutableExchange_";
channel.exchangeDeclare(myExchange, "topic", false, false, null);
channel.basicPublish(myExchange, "NO_KEY", isMandatory, null, "".getBytes());
For this there is something called PublisherAcknoledgement. This will basically gives an Ack to the publisher about the status of the message. You will be able to also differentiate between whether the message has reached till Exchange or it has reached till the consumer. You just have to handle each case properly.
This is a good way to know the status of the message being delivered. You might not know if its happening because of the wrong routing key but with doing various checks you might be able to narrow down to the result.
I'm using Azure Service Bus 1.1 (the on premise version)
I'm trying to set up a subscription that will receive messages that have not been filtered into any other existing subscription.
I have 3 console apps, one that creates topics and subscriptions, one that sends messages to the topic, and one that receives messages from a subscription.
I'm also using the Service Bus Explorer (V2.1) to see what is happening with my console apps.
I have tried setting up the topic as described on this page and this page which uses a MatchNoneFilterExpression but the example code does not compile(?) ie the FilterAction and FilterExpression properties are not in the RuleDescription class
RuleDescription matchNoneRule = new RuleDescription()
{
FilterAction = new SqlFilterAction("set defer = 'yes';"),
FilterExpression = new MatchNoneFilterExpression()
};
The RuleDescription class I'm using is in v2.1.0.0 of the Microsoft.ServiceBus.dll
It has the following properties available,
How do I send a message that matches no other filters to a particular subscription?
From this page which suggests setting the EnableFilteringMessagesBeforePublishing property on the topic.
It then suggests that on sending a message to this topic a message will trigger the NoMatchingSubscriptionException
I'm creating my topic with this code
var myTopic = new TopicDescription(topicName)
{
EnableFilteringMessagesBeforePublishing = true
};
namespaceManager.CreateTopic(myTopic);
I'm sending a message to the topic that doesn't match any filters and I can catch the exception and potentially resend the message with a property that does match a filter, e.g.:
try
{
topicClient.Send(message);
Console.WriteLine(string.Format("Message sent: Id = {0}, Body = {1}", message.MessageId, message.GetBody<string>()));
}
catch (NoMatchingSubscriptionException ex)
{
string messageBody = message.GetBody<string>();
BrokeredMessage msg = new BrokeredMessage(messageBody);
msg.Properties.Add("Filter", "NoMatch");
foreach (var prop in message.Properties)
{
msg.Properties.Add(prop.Key, prop.Value);
}
topicClient.Send(msg);
Console.WriteLine("\n NoMatchingSubscriptionException - message resent to NoMatchingSubscription");
Console.WriteLine(string.Format("Message sent: Id = {0}, Body = {1}", msg.MessageId, msg.GetBody<string>()));
}
I am using PushSharp to send Apple Push Notification in C# , i have my production .pem file and its password. Below is my code snippet.Am always getting this error ..
"A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted-"
OR
"System.IO.IOException: Authentication failed because the remote party has closed the transport stream."
I tried almost all codes available in net.Even tried MoonAPNS but same error, For custom script also am getting this SSPI failure error. I use the same .pem file and run a php script to send push notification to APN from same server,it works.
var push = new PushBroker();
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ck.pem"));
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "pwd"));
push.QueueNotification(new AppleNotification()
.ForDeviceToken("XXXXXXXXXXXXXXX")
.WithAlert("Hello World!")
.WithBadge(7)
.WithSound("sound.caf"));
LogManager.Info("Waiting for Queue to Finish..");
push.StopAllServices();
Please help
Thanks in advance
I think your c# may be incorrect, To verify, rather than with a .pem, can you try with your p12 cert using the below code as a test...
Boolean bsandbox = true;
string p12fileName =AppDomain.CurrentDomain.BaseDirectory + "yourCert.p12";
string p12password = "1234";
string deviceID1 = "2909b25e0c699b2dc4864b4b9f719e67aac7e0fab791a72a086ffb788ba28f6a"; //
string msg = "This is the message sent at : ";
string alert = "Hello world at " + DateTime.Now.ToLongTimeString();
int badge = 1;
string soundstring = "default";
var payload1 = new NotificationPayload(deviceID1, alert, badge, soundstring);
payload1.AddCustom("custom1", msg);
var notificationList = new List<NotificationPayload> { payload1 };
var push = new PushNotification(bsandbox, p12fileName, p12password);
var rejected = push.SendToApple(notificationList);`
I am trying to publish with Amazon's AWSSDK for C# and the Simple Notification Service.
There are no samples that come with the SDK and there are no samples anywhere on the web I could find after 2 hours of Googling. I came up with this but it is throwing an exception that yields no more information than the single string, "TopicARN" - no inner exception - nuffin!
If anyone has successfully sent a message with SNS via C# using the AWSSDK I would love to see even the most rudimentary working example. I am using the latest SDK 1.5x
Here's the code:
string resourceName = "arn:aws:sns:us-east-1:xxxxxxxxxxxx:StackOverFlowStub";
AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(accesskey,secretkey);
AddPermissionRequest permissionRequest = new AddPermissionRequest()
.WithActionNames("Publish")
.WithActionNames(accesskey)
.WithActionNames("PrincipleAllowControl")
.WithActionNames(resourceName);
snsclient.AddPermission(permissionRequest);
PublishRequest pr = new PublishRequest();
pr.WithMessage("Test Msg");
pr.WithTopicArn(resourceName);
pr.WithSubject("Test Subject");
snsclient.Publish(pr);
Here is a sample that creates a topic, sets a topic display name, subscribes an email address to the topic, sends a message and deletes the topic. Note that there are two spots where you should wait/check your email before continuing. Client is the client instance, topicName is an arbitrary topic name.
// Create topic
string topicArn = client.CreateTopic(new CreateTopicRequest
{
Name = topicName
}).CreateTopicResult.TopicArn;
// Set display name to a friendly value
client.SetTopicAttributes(new SetTopicAttributesRequest
{
TopicArn = topicArn,
AttributeName = "DisplayName",
AttributeValue = "StackOverflow Sample Notifications"
});
// Subscribe an endpoint - in this case, an email address
client.Subscribe(new SubscribeRequest
{
TopicArn = topicArn,
Protocol = "email",
Endpoint = "sample#example.com"
});
// When using email, recipient must confirm subscription
Console.WriteLine("Please check your email and press enter when you are subscribed...");
Console.ReadLine();
// Publish message
client.Publish(new PublishRequest
{
Subject = "Test",
Message = "Testing testing 1 2 3",
TopicArn = topicArn
});
// Verify email receieved
Console.WriteLine("Please check your email and press enter when you receive the message...");
Console.ReadLine();
// Delete topic
client.DeleteTopic(new DeleteTopicRequest
{
TopicArn = topicArn
});