Backendless Support
 
Answered

Why are messages being deleted after a short time?

After I use this code, I see the channel and the message appear on backendless console. But after a short time, it disappears. Why?

Backendless.Messaging.publish("channelName", MainActivity.valuesLocal.get(0), new AsyncCallback<MessageStatus>()

{

@Override

public void handleResponse( MessageStatus response )

{

Toast.makeText(getApplicationContext(), "response ok", Toast.LENGTH_LONG).show();

}

@Override

public void handleFault( BackendlessFault fault )

{

Toast.makeText(getApplicationContext(), "response down", Toast.LENGTH_LONG).show();

}

} );

Leave a Comment

Comments (20)

photo
1

Our system processes hundreds of thousands of messages. Storing each and every message would be extremely inefficient and costly.

Regards,

Mark

photo
1

but why then you call it messages? if i even can't realise even simple mechanic of messaging (like imessages for example) beatween 2 people. And anyway need to somehow keep all in date base and make code for it. or is there any other ways?

Thanks

photo
1

I am not going to argue what it should be called. We call it messages and that is not going to change.

Android, iOS, JS and Flex SDK include a ready-to-go example which demonstrates a "simple mechanic of messaging between 2 people"..

Please be specific and describe what you are trying to do and what seems to be the problem.

photo
1

oh... i'm not arguing :) just asking, no more :) Probably missed something in your example. Look through once more and let you know if will have a questions with more details. Thanks

photo
1

What do you develop for? iOS, Android, JS?

photo
1

iOS

photo
1

Try this:

  1. select your app in console
  2. click the Code Generation icon
  3. select iOS in the menu
  4. click Sample Chat under Messaging > Publish/Subscribe.

That will generate a project with source code for your app which demonstrates basic chat between 2 people.

Regards,

Mark

photo
1

I'm guessing Kirill meant keeping a chat history indefinitely

photo
1

Chat history can be implemented with custom server-side code. All one needs to do is to add a "beforePublish" or "afterPublish" handler and store the published messages in the Data service.

photo
1

Could you give us hint on how to do it in Javascript backend? This is what I have got so far from the generated code:

  1. Backendless.ServerCode.Messaging.beforePublish('*', function(req) {
  2. //add your code here
  3. var chatObject = new ChatMessage( {
  4. text: "", // how do I get it?
  5. userId: "",
  6. conversationId: "",
  7. });
  8. var savedContact = Backendless.Persistence.of( Contact ).save( chatObject );
  9. });

I'm looking at this in Java documentation

  1. public void beforePublish( RunnerContext context, Object message, PublishOptions publishOptions, DeliveryOptions deliveryOptions ) throws Exception

I didn't find anything similar in JS docs, neither How to get the message data so I can create a ChatMessage object?

photo
photo
1

Yep, but still will have a problem if user gets messages when he not in application. Then i probably need to use some timer to check server is there any new messages, or probably we could realise it on some other way? Could you help us manage this issue?

photo
1

Hi Kirill,

The best way to preserve messages is by writing custom server-code for the message "publish" event and store incoming messages in our data store. When users come online, your app would first check in the data store (using Data Service API) and then use messaging "subscribe" function to receive messages from the Messaging Service.

Does it make sense?

Regards,

Mark

photo
2

Hi Mark

Please would you give some code sample that implements message storing in data service?

1- which api should be used to check the new messages in data store?

2- How recipient to receive the stored message by subscribing ?

Regards

Mousa

photo
2

Am really scratching my head around this . Problem with implementing server-side-code, in Android, is one would need two adapters, one to populate data from the stored record API and another to populate from the messaging API. Which one do u show coz one cannot show both simultaneously ? i stand corrected.

photo
1

I apologize, I cannot understand what you're asking. Could you possibly rephrase the question(s)?

photo
1

He is trying to say he will need two different sources of data for the chat view. In iOS terms - datasources for ViewController, in Android terms adapters for Activity.

photo
2

In this case, creating a facade adapter that pulls data from both sources and returns a unified collection would be an approach I'd experiment with.

photo
1

The apparent problem is the synchronization - should the app fetch Messages or BackendlessEntities to fill UITableView (or ListView)?

Perhaps there ought to be yet another object - a ViewModel for the TableViewCell, that will be created with a Message or with Entity.

It really is a strange setup at least from my experience with other messaging systems like socket.io. I'm not sure if there is any performance advantage as we have to save the messages to the database anyway.

photo
photo
1

Hi! About messages history. Is there any way to enable this feature by default in local Backendless installation?

I mean without need to store history as Mark advised above.

Thanks in advance.

photo
1

Yes, it would be so much helpful and we dont have to implement any server side code.. Backendless is mBaaS and it is supposed to help the front end developers avoid writing any server side code..

Now, we have to move to QuickBlox to enable chat messaging.. And also paying Backendless..