I have mobile application which uses a backend services to register to Azure push notification. Things were working fine until 4 days ago where the most notifications are not delivered to the application.
I'm using Service Bus Queue and WebJob to send the notification and I can see things executed successfully for Android but the notifications most of the time doesn't deliver to the app and the notification State equals Enqueued and Success equals 0 and Failure equals 0
I updated Microsoft.ServiceBus to the latest version but that didn't resolve the issue.
Last thing, Apple notifications used to work successfully but now they are throwing exception "The remote server returned an error: (400) Bad Request. The supplied notification payload is invalid"
Does anyone face similar issues?
I have experienced the same issue when pushing notifications to iOS devices via Azure's Notification Hubs. I received the same error message when calling the "SendAppleNativeNotificationAsync" method on the hub.
I made sure that I had no illegal characters in my message by replacing "\" and "'". After reading a few posts regarding issues with max limit on notifications, we decided to limit our message size to 150 characters (a magic number, we didn't do any research to find out exactly how big a push notification message is allowed to be).
I also changed how the JSON payload was created, and I'm now using Newtonsoft.Json.Linq to create a JSON object with my payload. I previously created a simple json string for the payload, something like this :
var apnsMessage = "{\"aps\":{\"alert\":"+message+", \"sound\" : \"default\", \"badge\" : 1}}";
Now, my JSON object is created as so:
var jsonPayload = JObject.FromObject(new
{
aps = new { alert = message.Replace("\"", "").Replace("'", "") },
sound = "default",
badge = 1
});
and I send the notification like this:
await Hub.SendAppleNativeNotificationAsync(jsonPayload.ToString());
Hope this helps you (or anyone else with the same issue) :)
EDIT:
Here is a simple helper for trimming/truncating strings :)
private static string GetTrimmedAndTruncatedString(string source, int length)
{
return source.Length > length ? source.Substring(0, length) + "..." : source;
}
/Isa
Related
I've been recently having problems with my Service Bus queue. Random messages (one can pass and the other not) are placed on the deadletter queue with the error message saying:
"DeadLetterReason": "Moved because of Unable to get Message content There was an error deserializing the object of type System.String. The input source is not correctly formatted."
"DeadLetterErrorDescription": "Des"
This happens even before my consumer has the chance to receive the message from the queue.
The weird part is that when I requeue the message through Service Bus Explorer it passes and is successfully received and handled by my consumer.
I am using the same version of Service Bus either for sending and receiving the messages:
Azure.Messaging.ServiceBus, version: 7.2.1
My message is being sent like this:
await using var client = new ServiceBusClient(connString);
var sender = client.CreateSender(endpointName);
var message = new ServiceBusMessage(serializedMessage);
await sender.SendMessageAsync(message).ConfigureAwait(true);
So the solution I have for now for the described issue is that I implemented a retry policy for the messages that land on the dead-letter queue. The message is cloned from the DLQ and added again to the ServiceBus queue and for the second time there is no problems and the message completes successfully. I suppose that this happens because of some weird performance issues I might have in the Azure infrastructure. But this approach bought me some time to investigate further.
I created a topic "Messages" in my service bus instance, and added a new subscription to it. I can send messages to this topic and the Azure Function v3 trigger is activated just fine. The message is received and displayed in an instant.
When I add an sql filter to filter messages for a subscription it is not working anymore.
What I did so far.
Created an sql filter in the azure portal:
sys.Label = "Test" -> Not working as no messages are received anymore, even though I verified that the Label attribute is set.
sys.Label != "Test" Not working as no messages are received anymore, even though I verified that the Label attribute is set and not matching "Test"
sys.To = "Test" -> Not working, no messages are received. Verified that the messages contain the To member.
sys.Label is not Null -> This is strangely working.
What am I doing wrong here?
As stated in the comment, the solution to this question can be found in the Microsoft Q&A.
To prevent a loss of this solution I am going to post it here too:
The SQL filter value should be in single quotes 'test'
Example : sys.To = 'test'
Make sure that you are defining the message system properties while
sending the message to topic.
Source
If someone is caught off guard by the red single quotes. They are just red, but don't indicate that something is wrong with it. It will just work fine.
I have the logic below that I am using to peek at the messages on a subscription
var path = EntityNameHelper.FormatSubscriptionPath(TopicName, subscriptionName);
var receiver = new MessageReceiver(connection string, path);
var messages = await receiver.PeekAsync(1000);
When I look at Service Bus Explorer it shows that there are 800 messages on the subscription
However the logic only returns 23
Does anyone know why this happens, is there some kind of caching or something?
Paul
That's by design. Peek and receive operations will return as much as broker can at that specific moment. If you want to retrieve all the messages, you'd have to write some code to iterate over the request one or more time until the number of items you need is reached.
If you want to raise a broker request to clarify this, there's a service issue tracker here.
I am currently using two different platforms to perform sync actions. So, when action happens on platform 1 (C# -visual studio), that same action then needs to happen on platform 2 (Java). To do that, I use SB (Azure service bus) for sharing the Json messages between two platforms.
Action 1: platform 1 ----> Service bus -----> platform 2 .
Works fine. The message is sent and received exactly as it should be.
Action 2: platform 2 ----> Service bus ----> platform 1.
Does not work. The message is sent correctly to SB, but when it's picked up, the content property only contains an empty array, when it should be an array of bytes (containing the message). The other message attributes like contentType, replyTo and so on are set correctly, so the message is getting picked up fine. It's just that there is no content or in other words message body.
Action 3: Azure SB/Send messages -----> Service bus -----> platform 1.
Works fine. Another option is to send the JSON message directly to the Service Bus using Azure Service Bus/Send messages and put the JSON message in there.
For actions 2 and 3 exactly the same message is sent to the service bus (when I view it). One is sent directly to service bus, another is generated by the platform 2. I think the actual message somehow seems to be different in the background, which is why the message body is empty in the action 2.
Threads and processes are being handled correctly.
To set up receiver:
IMessageReceiver receive r= null;
if (config.isSessionsEnabled()) {
receiver = ClientFactory.acceptSessionFromConnectionStringBuilder(new ConnectionStringBuilder(connString), config.getSessionID(), ReceiveMode.PEEKLOCK);
} else {
receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder(new ConnectionStringBuilder(connString), ReceiveMode.PEEKLOCK);
}
For receiving message:
try {
message = receiver.receive(Duration.ofSeconds(1)); //message.Content will be empty array
if(message != null){
//process message
}
} catch (Exception e) {
}
}
Is my understanding correct or perhaps there is another explanation to it!
Is my understanding correct or perhaps there is another explanation to it!
It is very odd that if you send the message from Java platform and the content of message is empty.
Based on my understanding, it seems that message content is empty when you send to ABS. I recommand that you could check the Java send message code before sending to ABS.
You alse could use Azure Service bus exploer to get the message information after it sent to ABS [Before received from .Net platform].
I am subscribing to a channel in Pusher on my local machine using the Javascript SDK, and I don't get any error.
However, when I publish an event to that channel it is not received by the subscriber.
I've looked at Pusher's debug console and saw that the message is indeed sent but the subscription never occurs, as the connection is somehow interrupted, apparently prior to the subscription request (i.e I get a disconnection message, as shown in the console screenshot below).
the code is pretty boilerplate:
var pusher = new Pusher('PUSHER_KEY');
channel = pusher.subscribe('game' + game.gameId);
channel.bind('statusChange', function(game) {
console.log("GOT PUSHER - STATUS " + game.status);
$scope.game.status = game.status;
});
Examining the channel.subscribed property shows that the subscription failed as it equals false. I am at the sandbox plan (max 20 connections) and am only using 2 connections.
What can disrupt the connection?
The channel object:
Console screenshot:
I don't know what's the issue exactly but enabling the logs on the client side might help your find it:
Pusher.log = function(message) {
if (window.console && window.console.log) {
window.console.log(message);
}
};
There's some resources on the website to debug that kind of problem too: http://pusher.com/docs/debugging