Giter VIP home page Giter VIP logo

zerodep-web-push-java-example-webflux's Introduction

zerodep-web-push-java-example-webflux

A zerodep-web-push-java example using Spring WebFlux.

Also, this example demonstrates how to work with Reactor Netty HTTP Client

This example is sightly more complex but practical compared to zerodep-web-push-java-example and zerodep-web-push-java-example-vertx.

In this example, we demonstrate the error handling on requesting the delivery of push notifications.

This is the example for v2. The example for v1 is here.

Requirements

  • JDK17+
  • A library for generating ECDSA key pairs(e.g. OpenSSL)
  • A browser supporting Push API such as Google Chrome, Microsoft Edge and Firefox

Usage

  1. Set up and run the application.

    git clone https://github.com/st-user/zerodep-web-push-java-example-webflux.git
    cd zerodep-web-push-java-example-webflux
    mkdir .keys
    cd .keys
    openssl ecparam -genkey -name prime256v1 -noout -out my-private.pem
    openssl pkcs8 -in my-private.pem -topk8 -nocrypt -out my-private_pkcs8.pem
    openssl ec -in my-private.pem -pubout -conv_form uncompressed -out my-pub.pem
    cd ../
    

    Linux/mac OS

    ./mvnw clean
    ./mvnw spring-boot:run
    

    Windows

    ./mvnw.cmd clean
    ./mvnw.cmd spring-boot:run
    
  2. Open your browser and access http://localhost:8080;

  3. Click the subscribe button.

  4. Enter an arbitrary message and click the send button.

  5. You should see a push notification!

  6. (Optional) Since push notifications are handled in the background, we can get them even if we close the browser.

    • Close the browser and open a terminal instead.
    • Make the application send a push notification by using a command like the following:
    curl -X POST http://localhost:8080/sendMessage \  
    -H 'Content-Type: application/json' \
    -d '{ "message": "Message sent with curl." }'

NOTE

private key

In general, storing private keys in plain text on a file system is not recommended (In the above example, we do that for simplicity).

However, such a method is still useful depending on architectures.

For example:

Further reading

See also

zerodep-web-push-java-example-webflux's People

Contributors

st-user avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.