Thư viện máy chủ
Java thời gian thực với WebSocket Publish từ Spring Boot hoặc bất kỳ dịch vụ JVM nào.
Đăng nhập để xem các đoạn mã này với host cụm của riêng bạn. Đăng nhập
Đang dùng một AI agent lập trình? Sao chép prompt cho agent ↓
Cài đặt <dependency >
<groupId > com.pusher</groupId >
<artifactId > pusher-http-java</artifactId >
<version > 1.3.4</version >
</dependency > Publish một sự kiện Pusher pusher = new Pusher ("YOUR_APP_ID" , "YOUR_APP_KEY" , "YOUR_APP_SECRET" );
pusher.setHost("ws.hibira.io" );
pusher.setEncrypted(true );
pusher.trigger("orders" , "order-shipped" , Map.of("id" , 1024 ));Prompt cho agent Dán nội dung này vào Claude Code, Cursor, GitHub Copilot hoặc một AI agent lập trình khác, và nó sẽ tích hợp Hibira vào dự án Java của bạn với các cài đặt ở trên.
Integrate Hibira realtime messaging into this Java project. Hibira is a hosted WebSocket service that speaks the Pusher Channels protocol, so it works with the standard Pusher libraries (here: pusher-http-java, https://github.com/pusher/pusher-http-java) pointed at Hibira instead of pusher.com.
Connection details:
- Host: ws.hibira.io
- Port: 443
- TLS: yes (https)
- App ID: YOUR_APP_ID
- App key: YOUR_APP_KEY
- App secret: YOUR_APP_SECRET (server-side only)
What to do:
1. Look at the project first (framework version, package manager, config and env conventions, where similar integrations live) and follow what it already does.
2. Add the dependency with the project's build tool (Maven or Gradle).
3. In Spring Boot, expose the Pusher client as a singleton @Bean configured from application properties backed by environment variables.
4. If the front end subscribes to private or presence channels, add a controller endpoint that checks the user and returns pusher.authenticate(socketId, channel).
5. Read the credentials and host from environment variables or the project's config, and add placeholder entries to .env.example (or its equivalent). Never commit real values, and never send the app secret to a browser or mobile app.
6. Always pass the host, port and TLS setting above. The library defaults to pusher.com; where it requires a cluster, use "ap" (the host decides where it connects).
7. If YOUR_APP_KEY or YOUR_APP_SECRET above is still a placeholder, keep it as an env placeholder and tell me where to fill it in rather than inventing a value.
8. When you are done, list the files you changed and tell me how to check it works, for example by publishing a test event and watching it arrive.
Reference setup from the Hibira Java guide (adapt it to the project's structure):
Install:
```xml
<dependency>
<groupId>com.pusher</groupId>
<artifactId>pusher-http-java</artifactId>
<version>1.3.4</version>
</dependency>
```
Publish an event:
```java
Pusher pusher = new Pusher("YOUR_APP_ID", "YOUR_APP_KEY", "YOUR_APP_SECRET");
pusher.setHost("ws.hibira.io");
pusher.setEncrypted(true);
pusher.trigger("orders", "order-shipped", Map.of("id", 1024));
```
Thay YOUR_APP_KEY và các giá trị giữ chỗ khác bằng giá trị từ bảng điều khiển, hoặc để agent giữ chúng dưới dạng biến môi trường để bạn tự điền.
Hoặc kết nối máy chủ MCP của Hibira, và agent của bạn có thể tự tạo ứng dụng và điền thông tin xác thực. Kết nối AI agent lập trình của bạn →
Dùng app key và secret từ bảng điều khiển. Kênh, sự kiện và endpoint xác thực hoạt động y như với Pusher. Tài liệu thư viện ↗