ralscha / blog

Source code for my blog
https://golb.hplar.ch/
MIT License
222 stars 246 forks source link

sw-push, can you tell me messagingSenderId and gcm_sender_id are the same? #15

Closed skanel closed 6 years ago

skanel commented 6 years ago

1, gcm_sender_id in sw.js

  1. messagingSenderId in index.js

both are store the save value?

ralscha commented 6 years ago

Yes they are the same value. But don't copy my id it will not work. Use your own id.

The blog post shows you where you find it in the Firebase Console.

ralscha commented 6 years ago

Just realised there is no gcm_sender_id in sw.js. I guess you mean messagingSenderId

messagingSenderId in sw.js and index.js are the same value

ralscha commented 6 years ago

If you mean the gcm_sender_id in the manifest.json file, then it has to be 103953800507 This is a completely different number. See my blog post

Don't change the number 103953800507. This is a fixed number and all clients in the world, that are connected to FCM, use this same number.

{
"gcm_sender_id": "103953800507",
}
skanel commented 6 years ago

yes , I know how to create the sender_id, even I put

{
 "gcm_sender_id": "103953800507",
}

and test with many option i still get the same error , could you check your repos again?

Thank all of your response time.

skanel commented 6 years ago

how to put this file , is path like this?

fcm.service-account-file=C:\Users\Administrator\Documents\Projects\blog\sw-push\src\main\resources\qm-tracker-backend-firebase-adminsdk-wowh8-d8b0c278a7.json

ralscha commented 6 years ago

I tested it on my computer and it works. I updated the version on GitHub (Only upgraded the firebase library to 6.2.0)

My settings looks like this

fcm.service-account-file=D:/ws/blog/sw-push/pushdemo-91541-firebase-adminsdk-sltyt-65f32cb28a.json

Maybe try / instead of \

skanel commented 6 years ago

almost run now but get this

Sending chuck joke... 2018-06-11 16:33:18.284 ERROR 4812 --- [pool-1-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:169) ~[firebase-admin-5.10.0.jar:na] at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:140) ~[firebase-admin-5.10.0.jar:na] at com.google.firebase.messaging.FirebaseMessaging.getInstance(FirebaseMessaging.java:121) ~[firebase-admin-5.10.0.jar:na] at ch.rasc.swpush.fcm.FcmClient.send(FcmClient.java:52) ~[classes/:na] at ch.rasc.swpush.PushChuckJokeService.sendPushMessage(PushChuckJokeService.java:47) ~[classes/:na] at ch.rasc.swpush.PushChuckJokeService.sendChuckQuotes(PushChuckJokeService.java:32) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_171] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_171] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_171] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]

Sending chuck joke... 2018-06-11 16:33:48.761 ERROR 4812 --- [pool-1-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:169) ~[firebase-admin-5.10.0.jar:na] at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:140) ~[firebase-admin-5.10.0.jar:na] at com.google.firebase.messaging.FirebaseMessaging.getInstance(FirebaseMessaging.java:121) ~[firebase-admin-5.10.0.jar:na] at ch.rasc.swpush.fcm.FcmClient.send(FcmClient.java:52) ~[classes/:na] at ch.rasc.swpush.PushChuckJokeService.sendPushMessage(PushChuckJokeService.java:47) ~[classes/:na] at ch.rasc.swpush.PushChuckJokeService.sendChuckQuotes(PushChuckJokeService.java:32) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171] at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_171] at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_171] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_171] at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_171] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_171] at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171]

ralscha commented 6 years ago

Can you try 6.2.0. That's the version I tested and works on my computer

<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.2.0</version>
skanel commented 6 years ago

Good now,

=========|_|==============|__/=//// :: Spring Boot :: (v2.0.2.RELEASE)

2018-06-11 16:39:16.420 INFO 3096 --- [lication.main()] ch.rasc.swpush.Application : Starting Application on WIN-5LEI70KI9L7 with PID 3096 (C:\Users\Administrator\Documents\Projects\blog\sw-push\target\classes started by Administrator in C:\Users\Administrator\Documents\Projects\blog\sw-push) 2018-06-11 16:39:16.420 INFO 3096 --- [lication.main()] ch.rasc.swpush.Application : No active profile set, falling back to default profiles: default 2018-06-11 16:39:16.528 INFO 3096 --- [lication.main()] onfigReactiveWebServerApplicationContext : Refreshing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5584c05f: startup date [Mon Jun 11 16:39:16 ICT 2018]; root of context hierarchy 2018-06-11 16:39:19.277 INFO 3096 --- [lication.main()] s.w.r.r.m.a.RequestMappingHandlerMapping : Mapped "{[/register],methods=[POST]}" onto public void ch.rasc.swpush.RegistryController.register(reactor.core.publisher.Mono) 2018-06-11 16:39:19.432 INFO 3096 --- [lication.main()] o.s.w.r.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler] 2018-06-11 16:39:19.432 INFO 3096 --- [lication.main()] o.s.w.r.handler.SimpleUrlHandlerMapping : Mapped URL path [/] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler] 2018-06-11 16:39:19.668 INFO 3096 --- [lication.main()] o.s.w.r.r.m.a.ControllerMethodResolver : Looking for @ControllerAdvice: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@5584c05f: startup date [Mon Jun 11 16:39:16 ICT 2018]; root of context hierarchy 2018-06-11 16:39:20.870 ERROR 3096 --- [lication.main()] ch.rasc.swpush : init fcm

java.nio.file.NoSuchFileException: qm-tracker-backend-firebase-adminsdk-wowh8-d8b0c278a7.json at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79) ~[na:1.8.0_171] at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97) ~[na:1.8.0_171] at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102) ~[na:1.8.0_171] at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230) ~[na:1.8.0_171] at java.nio.file.Files.newByteChannel(Files.java:361) ~[na:1.8.0_171] at java.nio.file.Files.newByteChannel(Files.java:407) ~[na:1.8.0_171] at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384) ~[na:1.8.0_171] at java.nio.file.Files.newInputStream(Files.java:152) ~[na:1.8.0_171] at ch.rasc.swpush.fcm.FcmClient.(FcmClient.java:31) ~[classes/:na] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.8.0_171] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [na:1.8.0_171] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.8.0_171] at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [na:1.8.0_171] at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:170) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:271) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1274) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1131) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:61) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) ~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at ch.rasc.swpush.Application.main(Application.java:18) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_171] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171] at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:496) ~[na:na] at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]

2018-06-11 16:39:25.959 INFO 3096 --- [lication.main()] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-06-11 16:39:26.037 INFO 3096 --- [lication.main()] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing

ralscha commented 6 years ago

Here is the error. The file does not exist

java.nio.file.NoSuchFileException: qm-tracker-backend-firebase-adminsdk-wowh8-d8b0c278a7.json
skanel commented 6 years ago

awesome now,

. _ _ /\ / '_ () \ \ \ \ ( ( )\ | ' | '| | ' \/ ` | \ \ \ \ \/ _)| |)| | | | | || (| | ) ) ) ) ' |__| .|| ||| |\, | / / / / =========|_|==============|__/=//// :: Spring Boot :: (v2.0.2.RELEASE)

2018-06-11 16:54:30.481 INFO 5260 --- [ main] ch.rasc.swpush.Application : Starting Application on WIN-5LEI70KI9L7 with PID 5260 (C:\Users\Administrator\Documents\Projects\blog\sw-push\target\classes started by Administrator in C:\Users\Administrator\Documents\Projects\blog\sw-push) 2018-06-11 16:54:30.481 INFO 5260 --- [ main] ch.rasc.swpush.Application : No active profile set, falling back to default profiles: default 2018-06-11 16:54:30.653 INFO 5260 --- [ main] onfigReactiveWebServerApplicationContext : Refreshing org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@27cd4a7e: startup date [Mon Jun 11 16:54:30 ICT 2018]; root of context hierarchy 2018-06-11 16:54:33.292 INFO 5260 --- [ main] s.w.r.r.m.a.RequestMappingHandlerMapping : Mapped "{[/register],methods=[POST]}" onto public void ch.rasc.swpush.RegistryController.register(reactor.core.publisher.Mono) 2018-06-11 16:54:33.463 INFO 5260 --- [ main] o.s.w.r.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler] 2018-06-11 16:54:33.463 INFO 5260 --- [ main] o.s.w.r.handler.SimpleUrlHandlerMapping : Mapped URL path [/] onto handler of type [class org.springframework.web.reactive.resource.ResourceWebHandler] 2018-06-11 16:54:33.729 INFO 5260 --- [ main] o.s.w.r.r.m.a.ControllerMethodResolver : Looking for @ControllerAdvice: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@27cd4a7e: startup date [Mon Jun 11 16:54:30 ICT 2018]; root of context hierarchy 2018-06-11 16:54:40.244 INFO 5260 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2018-06-11 16:54:40.288 INFO 5260 --- [ main] s.a.ScheduledAnnotationBeanPostProcessor : No TaskScheduler/ScheduledExecutorService bean found for scheduled processing 2018-06-11 16:54:40.543 INFO 5260 --- [ main] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080 2018-06-11 16:54:40.621 INFO 5260 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080 2018-06-11 16:54:40.633 INFO 5260 --- [ main] ch.rasc.swpush.Application : Started Application in 12.259 seconds (JVM running for 26.647) Sending chuck joke... Sent message: projects/qm-tracker-backend/messages/7308348122207366006 Sending chuck joke... 2018-06-11 16:55:16.513 WARN 5260 --- [ctor-http-nio-3] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/favicon.ico]: Response status 404 Sent message: projects/qm-tracker-backend/messages/5393624579922890064 1 tokens were subscribed successfully

ralscha commented 6 years ago

Looks good. Do you see the messages in the browser?

skanel commented 6 years ago

it works now my hero, thank you so much for you times and your responsibility, I really really appreciate it.

ralscha commented 6 years ago

No problem. Happy that I was able to help.