Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate messages when using send batch of messages #372

Open
dongphh opened this issue Dec 25, 2023 · 0 comments
Open

duplicate messages when using send batch of messages #372

dongphh opened this issue Dec 25, 2023 · 0 comments

Comments

@dongphh
Copy link

dongphh commented Dec 25, 2023

[READ] Step 1: Are you in the right place?

  • For issues related to the code in this repository file a Github issue.
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: window 10 (19045)
  • Firebase SDK version: 2.4.0 with VS2019
  • Firebase Product: messaging (auth, database, storage, etc)
  • .NET version: 4.6.1
  • OS: windows dotnet

[REQUIRED] Step 3: Describe the problem

Steps to reproduce:

When I send a list of messages using sendEachAsync method with data read all info from my DB (about 10000 users) and loop each 500 record and send batch then received duplicate messages.

I using code follow in doc:
https://firebase.google.com/docs/cloud-messaging/send-message

Relevant Code:

if (FirebaseApp.DefaultInstance == null)
{
FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile(Server.MapPath(ConfigurationManager.AppSettings["FCMKey"]))
});
}

var messages = new List()
int cnt = 0;
foreach (DataRow item in iResult.CursorData.Rows)
{
cnt++;

                            messages.Add(new Message()
                            {
                                Notification = new Notification()
                                {
                                    Title = item["title"].ToString(),
                                    Body = item["DESCRIPTION"].ToString()
                                },
                                Token = item["GCMID"].ToString()
                            });
                           
                            if (cnt == 500 || cnt==iResult.CursorData.Rows.Count)
                            {
                                try
                                {
                                   
                                    string Obj = fcm.SendMultiNotiV2(messages);
                                    messages.Clear();
                                    
                                }
                                catch (Exception ex)
                                {
                                    messages.Clear();                                        
                                }
                                finally
                                {
                                    cnt = 0;
                                    messages.Clear();
                                  
                                }
                            }
                        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants