I send push notifications using PushSharp.
I am facing a problem while receiving the responses in the delegate methods as mentioned in Redth documentation on GitHub.
So, of the say 10 GCM Registration Ids that I send a particular message, I receive 9 responses only. I require this kind of response to make sure that in case of canonical Ids returned I should be able to update my database accordingly.
Is this behavior by design (i.e to not wait for all the responses from GCM) which results in few responses getting dropped ?
Below is my code snippets for better understanding
//Create our push services broker
//Create our push services broker
var broker = new PushBroker();
broker.OnNotificationSent += new NotificationSentDelegate(NotificationSent);
broker.OnNotificationFailed += new PushSharp.Core.NotificationFailedDelegate(NotificationFailed);
broker.OnChannelException += new ChannelExceptionDelegate(ChannelException);
broker.OnServiceException += new ServiceExceptionDelegate(ServiceException);
broker.OnDeviceSubscriptionChanged += new DeviceSubscriptionChangedDelegate(DeviceSubscriptionChanged);
broker.OnDeviceSubscriptionExpired += new PushSharp.Core.DeviceSubscriptionExpiredDelegate(DeviceSubscriptionExpired);
broker.OnChannelCreated += new ChannelCreatedDelegate(ChannelCreated);
broker.OnChannelDestroyed += new ChannelDestroyedDelegate(ChannelDestroyed);
//---------------------------
// ANDROID GCM NOTIFICATIONS
//---------------------------
broker.RegisterGcmService(new GcmPushChannelSettings(senderID, senderAuthToken, applicationIdPackageName));
GcmNotification gcm = new GcmNotification();
gcm.RegistrationIds.Add(deviceRegistrationId1);
gcm.RegistrationIds.Add(deviceRegistrationId2);
//and so on
gcm.WithJson("{\"Test\":\"" + notificationMsg + "\",\"badge\":7,\"sound\":\"sound.caf\"}");
//Stop and wait for the queues to drains
broker.StopAllServices(true);
//<
Please advise if I am missing something in this implementation.
Thanks in advance
You're not registering to see the failed notifications as you associate the delegate with the PushSharp delegate and not your own:
broker.OnNotificationFailed += new PushSharp.Core.NotificationFailedDelegate(NotificationFailed);
should match your:
broker.OnNotificationSent += new NotificationSentDelegate(NotificationSent);
Related
Currently, I have dozens of .NET services hosted on various machines that show up as Resources on my AppInsights Application Map, which also shows their dependencies with respect to each other, based on the HTTP requests they make.
However, the relationships between services that communicate through NServiceBus (RabbitMQ) are not shown. Now, I am able to show the messages that are either sent or handled by a service via calls to TelemetryClient.TrackXXX(), but not connect Resources on the map using this information.
I have even gone so far as to attach the parent operation ID from the NSB message sender to the message itself, and assign it to the telemetry object in the receiver, but there is still no line drawn between the services in the Application Map.
To reiterate, this is what I'm getting in the Application Map:
(NSB Message Sender) --> (Message sent/handled)
And this is what I want:
(NSB Sender) --> (Receiver)
The services in question are .NET Core 3.1.
I cannot provide the code, as this is for my work, but any help would be greatly appreciated. I've searched everywhere, and even sources that seemed like they would help, didn't.
(not signed in, posting from work)
Alright, I finally got it. My approach to correlate AppInsights resources using their NSB communication is to mimic HTTP telemetry correlation.
Below is an extension method I wrote for AppInsights' TelemetryClient. I made a subclass named RbmqMessage:NServiceBus.IMessage, given my applications use RBMQ, and gave it the following properties for the sake of correlation (all set in the service that sends the message) :
parentId: equal to DependencyTelemetry.Id
opId: value is the same in the sender's DependencyTelemetry and the receiver's RequestTelemetry. Equal to telemetry.context.operation.id
startTime: DateTime.Now was good enough for my purposes
The code in the service that sends the NSB message:
public static RbmqMessage TrackRbmq(this TelemetryClient client, RbmqMessage message)
{
var msg = message;
// I ran into some issues with Reflection
var classNameIdx = message.ToString().LastIndexOf('.') + 1;
var messageClassName = message.ToString().Substring(classNameIdx);
var telemetry = new DependencyTelemetry
{
Type = "RabbitMQ",
Data = "SEND "+messageClassName,
Name = "SEND "+messageClassName,
Timestamp = DateTime.Now,
Target = "RECEIVE "+messageClassName //matches name in the service receiving this message
};
client.TrackDependency(telemetry);
msg.parentId = telemetry.Id;
msg.opId = telemetry.Context.Operation.Id; //this wont have a value until TrackDependency is called
msg.startTime = telemetry.Timestamp;
return msg;
}
The code where you send the NSB message:
var msg = new MyMessage(); //make your existing messages inherit RbmqMessage
var correlatedMessage = _telemetryClient.TrackRbmq(msg);
MessageSession.Publish(correlatedMessage); //or however the NSB message goes out in your application
The extension method in the NServiceBus message-receiving service:
public static void TrackRbmq(this TelemetryClient client, RbmqMessage message)
{
var classnameIdx = message.ToString().LastIndexOf('.')+1;
var telemetry = new RequestTelemetry
{
Timestamp = DateTime.Now,
Name = "RECEIVE "+message.ToString().Substring(classNameIdx)
};
telemetry.Context.Operation.ParentId = message.parentId;
telemetry.Context.Operation.Id = message.opId;
telemetry.Duration = message.startTime - telemetry.Timestamp;
client.TrackRequest(telemetry);
}
And finally, just track and send the message:
var msg = new MyMessage();
_telemetryClient.TrackRbmq(msg);
MessagePipeline.Send(msg); //or however its sent in your app
I hope this saves someone the trouble I went through.
I am looking for a way to use Campaign Monitor's API in my ASP.NET/VB Web application.
I have not used any API before, thus reading their documentation is very difficult to understand.
If anyone has used it and is able to provide some instructions I would appreciate it; or if someone has some general usage instructions (if applied on any APi), be my guest! :)
I know this is not the typical "I have a problem and this is my problem and here's my effort so far" but any help would be much appreciated.
You can also use the Campaign Monitor API client library which is available on Nuget:
AuthenticationDetails auth = new ApiKeyAuthenticationDetails(apiKey);
var fields = new List<SubscriberCustomField>() {
new SubscriberCustomField() { Key = "MyCustomField", Value = myVal }
};
var subscriber = new Subscriber(auth, listId);
subscriber.Add(email, fullName, fields, false);
I use campaign monitor for populating subscriber lists.
There are two methods to post your subscribers to lists. I'm going to stick to the simplest one. Let's round up somethings you need first.
You'll need an API key (which I am sure you have).
You'll need to create a subscribers list and after you create this
list you'll need the list ID. To get the ID (which is wierd).You'll
need to click into your subscriber list. This look for this towards
the top. Single opt-in list (change name/type) Note: You are not
going to change the name or edit anything but you have to click in
here to get the ID. On the third section you will see this: API
Subscriber List ID. If you're using the API, you'll need this ID to
access this list. 000x0000xx0x0xx00x00xx (just an example.)
You'll need a form to capture Name and Email. You'll need your listid which
you got in the previous point.
Then you'll need to code a communication object.
If you are doing a straight forward call you'll need the name, email, and listid.
ListID ="000x0000xx0x0xx00x00xx";
Email ="JoeM#somethingemail.com";
Name = "Joe Middle";
APIKey = yourAPIKey;
APIURL = "http://api.createsend.com/";
ApiCall = variables.APIURL;
ApiCall &= "api/api.asmx/Subscriber.Add?ApiKey=" & variables.APIKey;
ApiCall &= "&ListID=" & URLEncodedFormat(arguments.ListID);
ApiCall &= "&Email=" & URLEncodedFormat(arguments.Email);
ApiCall &= "&Name=" & URLEncodedFormat(arguments.Name);
Once you have your url build you use whatever method .net uses to post http.
Then you'll want to code for success or fail and do something with that info. post to http and call the result. apiResult.
apiResult = xmlParse(apiResult.fileContent);
try {intCount = ArrayLen(apiResult.Result.XMLChildren);}
catch(Any e){intCount = 0;}
if (intCount gt 0){apiResult = apiResult.Result.xmlChildren;}
// Error handling
if ( apiResult[1].xmlName eq "Code" and apiResult[2].xmlName eq "Message" ){
returnStruct['blnSuccess'] = 0;
returnStruct['errorCode'] = apiResult[1].xmlText;
returnStruct['errorMessage'] = apiResult[2].xmlText;
}
// Success
else {
// Return str
returnStruct['blnSuccess'] = 1;
returnStruct['returnString'] = apiResult.Result.xmlText;
}
The code above was adapted from coldfusion and I didn't build it but it is cfscript which is not CFML and you can kind of interpret what is happening.
If you adapt this to .NET then all you are missing is your HTTP call stuff method.
To check log into Campaign Monitor and click on your list. You should see additions showing up, if not it is either you API key (not usually the case), your listID (could be the case), your code (most likely culprit).
This was hammered out in a hurry so apologies if the flow is weird.
Good luck!
I am currently working with Flex 4.9 (Mobile App) and BlazeDS integrated with ColdFusion. I have created a simple producer/consumer application where is sends up the object to the server, stores the object, then sends the object to all the connected clients. This is working very well.
However, my only issue is that the client who sent the object, is also receiving it right back. I would prefer this not happen. Is there anyway on the client side, to distinguish if you are the originator.
I understand that the event from the consumer has an originatorID but I have no idea what to match the ID too on return.
Message Handler:
protected function consumer_messageHandler(event:MessageEvent):void
{//Need to check if client is the same HERE
var t:Object = event.message.body.ticket;
var i:ArrayCollection = event.message.body.TI;
if (t != null && t.length > 0)
{
var v:views.delivery.HomeView = this.mainNav.activeView as views.delivery.HomeView;
var dao:DTDAO = new DTDAO();
var t:Object = t.getItemAt(0);
dao.syncDeliveryT(ticket, items);
}
}
I am developing a simple tcp server with qt. There is no problem with that. But the problem is, i have listed every connected client in a listbox and i want to see the incoming data only from the selected client from the listbox but i can only see the last connected client's messages.
here is the code,
this is the constructor part
server = new QTcpServer();
client = new QTcpSocket();
connect(server, SIGNAL(newConnection()),this, SLOT(acceptConnection()));
server->listen(QHostAddress::Any, ui->txtPort->text().toInt(bool(),10));
if(server->isListening())
{
ui->statusBar->showMessage("Server Started..");
}
else
{
ui->statusBar->showMessage("Server Not Started..");
}
connect(client,SIGNAL(disconnected()),this,SLOT(client_disconnected()));
connect(ui->listWidget,SIGNAL(clicked(QModelIndex)),this,SLOT(selected_client()));
here is acceptConnection() part
client = server->nextPendingConnection();
ui->listWidget->insertItem(client_count,client->peerAddress().toString());
client_count++;
and this is the listWidget item's selected item event
ui->txtRead->clear();
selected_client_index = ui->listWidget->currentIndex().row();
connect(client, SIGNAL(readyRead()),this, SLOT(startRead()));
and lastly the startRead() part
char buffer[1024] = {0};
client->read(buffer, client->bytesAvailable());
qDebug() << buffer;
ui->txtRead->insertPlainText(buffer);
How can i select the specific client and show its messages ?
Thanks in advance.
You should not use client in startRead, but some selectedClient, that You remembers in selected_client() SLOT.
As for now, when You use client = server->nextPendingConnection(), You are losing any previous clients. You should save them into some QList<QTcpSocket*>.
I'm using Adobe Stratus (now renamed to Cirrus) to build a p2p application. Inside the application, I used NetStream.onPeerConnect callback function and expected it to be triggered every time when a peer is connected. However, it always failed with my friend A while strangely friend B managed to have the function called without any problem.
I was wondering what could be the cause to this issue?
Here are how the code pieces look like.
First of all, create a NetConnection.
netConnection = new NetConnection();
netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
netConnection.connect(SERVER_ADDRESS+DEVELOPER_KEY);
Secondly, create NetStream upon NetConnection successfully connected.
private function netConnectionHandler(event:NetStatusEvent):void{
switch (event.info.code){
case "NetConnection.Connect.Success":
sendStream = new NetStream(netConnection, NetStream.DIRECT_CONNECTIONS);
sendStream.addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);
var sendObj:Object = new Object();
sendObj.onPeerConnect = function(subscriber:NetStream) : Boolean {
trace("[onPeerConnect] far id: " + subscriber.farID);
return true;
}
sendStream.client = sendObj;
sendStream.publish("file");
......
Thirdly, here's how I build the connection between two peers
receivedStream = new NetStream(netConnection, farId);
receivedStream.client = this;
receivedStream.addEventListener(NetStatusEvent.NET_STATUS, incomingStreamHandler);
receivedStream.play("file");
Please help enlighten me. Thanks!
It turns out my friend A is behind a symmetric NAT. I'm thinking to setup a TURN server for us to build a successful connection.