https://github.com/mawngo/fastwebpush4j
Optimized webpush library for java
https://github.com/mawngo/fastwebpush4j
java-library webpush
Last synced: 5 months ago
JSON representation
Optimized webpush library for java
- Host: GitHub
- URL: https://github.com/mawngo/fastwebpush4j
- Owner: mawngo
- License: mit
- Created: 2024-07-03T06:00:17.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-07-14T17:04:35.000Z (7 months ago)
- Last Synced: 2025-07-14T21:31:25.712Z (7 months ago)
- Topics: java-library, webpush
- Language: Java
- Homepage: https://central.sonatype.com/artifact/io.github.mawngo/fastwebpush4j
- Size: 104 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fast Webpush for Java
Implement of VAPID webpush that sacrifice security and feature for raw speed.
This library use jetty client to send push for better http2 performance over java `HttpClient`, thus make the minimum
supported java version to be at least 17.
## Installation
Require java 17+. For java 11 support: check [java11 branch](https://github.com/mawngo/fastwebpush4j/tree/java11)
Add library to gradle dependencies.
```groovy
dependencies {
implementation 'io.github.mawngo:fastwebpush4j:2.0.0'
}
```
## Optimization
This library provides some optimizations that can be enabled when creating `VapidPusher`.
- `vapidTokenTTL`: Caching vapid jwt token, and local public key + secret for each host. This optimization is enabled by
default and can be disabled by setting it to `0`.
- `localSecretTTL`: Enable local public key and secret reuse. When enabled, the pusher
will reuse the local public key and secret if provided in `Subscription.LocalKey` otherwise it generates secret and
local public key to `Subscription.LocalKey`. We can save those cases for reuse for the later push to the same
`Subscription`.
- `withRandom`: Allow to configure alternative `Random` implementation.
## Example Usage
```java
package io.github.mawngo.fastwebpush4j.example;
import io.github.mawngo.fastwebpush4j.Subscription;
import io.github.mawngo.fastwebpush4j.VapidPusher;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) throws Exception {
// Preparation
final var privateKey = "";
final var publicKey = "";
final var sub = new Subscription(
"",
new Subscription.Keys(
"",
""
)
);
// Build the pusher.
final var pusher = VapidPusher.builder("example@example.com", publicKey, privateKey)
.vapidTokenTTL(2, TimeUnit.HOURS) // Configure vapid and local keypair cache time.
.localSecretTTL(10, TimeUnit.HOURS) // Enable local public key and secret caching.
.build();
// Send the message.
final var res = pusher.prepareRequest("Test".getBytes(), sub).send();
System.out.println(res.getStatus());
// Close after used.
pusher.close();
}
}
```