Blackberry SendListener is called multiple times - blackberry

I have the following code in my app which listens and increments the counter when an sms is sent.
SendListener smsListener = new net.rim.blackberry.api.sms.SendListener() {
public boolean sendMessage(Message message) {
++smsCount;
return true;
}
};
However, for some reason the sendMessage method is called multiple times (usually this is 3 times) when only a single sms is send (even when the sms message is very short).
Why is this ? Is there a workaround for this problem ?

I didn't find mention about this issue on bb dev forum. As Emmanuel suggested you probably register listener several times. Please review this thread:
http://supportforums.blackberry.com/t5/Java-Development/sendListener-sms-and-folder-listner-invalk-multiple-times/m-p/1978915/highlight/true#M211297

Related

MQTT shared subscription

With a MQTT shared subscription, the message on the subscirbed topic would only be sent to one of the subscribing clients. Then, how the other clients of the group receive the message as they also subscribe to the same topic?
With a MQTT shared subscription, the message on the subscribed topic would only be sent to one of the subscribing clients.
Correct. With a normal (non‑shared) subscription the messages are sent to ALL subscribers; with shared subscriptions they are sent to ONE subscriber.
Prior to the introduction of shared subscriptions it was difficult to handle situations where you want multiple servers (for fault tolerance, load balancing etc) but only want to process each message once. Shared subscriptions provide a simple way of accomplishing this.
Then, how the other clients of the group receive the message as they also subscribe to the same topic?
If they are subscribing to the same shared subscription (with the same ShareName) then only one will receive the message; this is by design. If you want them all to receive the message then don't use a shared subscription. Alternatively you can establish multiple subscriptions (so all subscribers receive the message but only one processes it - but note the "could") as per the spec:
If a Client has a Shared Subscription and a Non‑shared Subscription and a message matches both of them, the Client will receive a copy of the message by virtue of it having the Non‑shared Subscription. A second copy of the message will be delivered to one of the subscribers to the Shared Subscription, and this could result in a second copy being sent to this Client.
There is an interesting bug in Java Paho (1.2.5) client that prevents working with shared topics that contains wildcards (#, +) https://github.com/eclipse/paho.mqtt.java/issues/827
Long story short, this will not work:
mqttClient.subscribe("$shared/group/some_topic/#", 1, (topic, message) -> System.out.println(topic));
instead it's required to use callbacks:
mqttClient.subscribe("$shared/group/some_topic/#", 1);
mqttClient.setCallback(new MqttCallback() {
#Override
public void connectionLost(final Throwable cause) {
}
#Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
System.out.println(topic);
}
#Override
public void deliveryComplete(final IMqttDeliveryToken token) {
}
});

Proper way to NOT send a reply back from webhook

I have setup a webhook and everything is working properly, however iam used to using a long number where STOP is handled automatically, but now I have a short code where we have to handle STOP ourselves. This isnt an issue on sending a message as I can check with my 'blacklist' numbers before sending the message. My question is in the Reply webhook, what is the best way or standard way to NOT send the reply message.
Below is twilios sample code (i added the comment where i would check if they are black listed)
public class SmsController : TwilioController
{
public TwiMLResult Index(SmsRequest incomingMessage)
{
var messagingResponse = new MessagingResponse();
// check for phone number in blacklist to NOT SEND
messagingResponse.Message("The copy cat says: " +
incomingMessage.Body);
return TwiML(messagingResponse);
}
}
If the number is blacklisted and i dont want to send the reply how do I "gracefully" not reply to them as this example takes a TwiMLResult and message response. Do i just set the message to an empty string ? do I return null? Any thoughts ? Thank you !

getting null response from recieveAndConvert() spring -amqp

I have created on replyQ and done biniding with one direct exchange.
Created the message by setting replyto property to "replyQ"
And sending the message on rabbit to the other service.
The service at other end getting the message and sending reply on given replyTo queue.
and now I am trying to read from a replyQ queue using
template.receiveAndConvert(replyQueue));
But getting null response and i can see the message in the replyQ.
That is the service is able to send the reply but am not able to read it from the given queue
Please help what is going wrong.
template.receiveAndConvert() is sync, blocked for some time one time function, where default timeout is:
private static final long DEFAULT_REPLY_TIMEOUT = 5000;
Maybe this one is your problem.
Consider to switch to ListenerContainer for continuous queue polling.
Another option is RabbitTemplate.sendAndReceive(), but yeah, with fixed reply queue you still get deal with ListenerContainer. See Spring AMQP Reference Manual for more info.
I don't know if this could help anyone, but I found out that declaring the expected Object as a parameter of a method listener did the work
#RabbitListener(queues = QUEUE_PRODUCT_NEW)
public void onNewProductListener(ProductDTO productDTO) {
// messagingTemplate.receiveAndConvert(QUEUE_PRODUCT_NEW) this returns null
log.info("A new product was created {}", productDTO);
}

Get iOS client to respond to SignalR request when app is backgrounded

I'm quite new to xamarin iOS programming, so this might be a dumb question..
Background:
I'm making an application that should send alarms to users within a certaint range of an incident location. Sice the incidens can happen "anywhere", geofencing is not an option. I have tried using remote notifications, but I need to alert just the clients that is within range of incident, and not disturb the rest of the clients (that are too far from the incident). That means that i first have to get the current location of all users, and the notify just the ones that are within range. So i thought maybe SignalR might be a solution.
How can i get the ios application (iOS 7 and 8) to respond to a request from a SignalR hub when the application is backgrounded (as in user pressed home button on phone so that the application is no longer in the foreground). I need to be able to ask the client to send its current location back to the server when the server requests it. I might add that the client sends significant location changes back to the server, so the application is enabled for background tasks.
I have set up the hub to send a GetLocation request:
public void SendLocationRequest()
{
Clients.Others.locationRequestReceived();
}
On the client in the ViewDidLoad method:
_client.OnLocationRequestReceived +=
(sender, message) => InvokeOnMainThread(() => LocRequestReceived());
and the LocReuestReceived (i have just set it up to display a local notification for now):
void LocRequestReceived()
{
var notification = new UILocalNotification
{
FireDate = DateTime.Now.AddSeconds(1),
AlertAction = "Get Location",
AlertBody = "Should retrieve currentLocation",
ApplicationIconBadgeNumber = 1,
SoundName = UILocalNotification.DefaultSoundName
};
UIApplication.SharedApplication.ScheduleLocalNotification(notification);
}
this woks fine as long as the app is on the foreground on the phone, but nothing happens when the app is bacgrounded. (it works on the simulator when backgrounded, but that migh be a bug in the simulator see http://krumelur.me/2014/09/23/my-ios8-adventure-as-a-xamarin-developer/ )
I quess my problem is that im calling InvokeOnMainThread(() => LocRequestReceived()), where I should perhaps call it on a background thread??
As i've said, i just started xamarin iOS development, so any input is greatly appreciated.
I ended up with a slightly different approach. I used native CFStreams to set up a persistent tcp connection instead of SignalR.
public CFReadStream readStream;
public CFWriteStream writeStream;
public void Connect()
{
if (readStream == null) {
CFStream.CreatePairWithSocketToHost ("SERVER_ADDRESS", "PORT", out readStream, out writeStream);
ConfigureStream (readStream);
//Added handler for streamevents
.....
readStream.Open ();
}
}
To enable the stream to be open even if app is backgrounded, this is essential (in addition to add the necessary background modes in Info.plist):
void ConfigureStream(CFStream stream)
{
var nsstream = new NSStream (stream.Handle);
if (stream.GetType () == typeof(CFReadStream)) {
**nsstream [NSStream.NetworkServiceType] = NSStream.NetworkServiceTypeVoIP;**
}
}

How to know the current state of application invoked in blackberry?

Is it possible to know the state of application invoked in blackberry? For example, if we invoke blackberry email application after sending an email, can we know if the application has closed or still running and also where the email has been sent, the subject, the content, etc.? The code may be something like this:
try {
Message message = new Message();
Address address = new Address("email#yahoo.com", "Email");
Address[] addresses = {address};
message.addRecipients(RecipientType.TO, addresses);
message.setContent("Testing email from MyTabViewDemo application");
message.setSubject("Testing Email");
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
log.debug(MyApp.GUID_LOG, "Send email action done!");
} catch (Exception e) {
Dialog.inform(e.toString());
}
and how about retrieving the state of other applications like phone, sms, camera?
Thank you.
You can view the visible applications by calling
ApplicationManager.getApplicationManager().getVisibleApplications();
That returns an array of application descriptors. From a descriptor, you can know the names and ids.
It is possible, however, that the messaging app is always on background and cannot be closed (I'm not 100% sure here)
But you can't know if a message has ben sent or not sending the mail like that.

Resources