Skip to content

Socket Holder is a socket management framework. Its core functions include socket management, business subscription, and service cluster broadcast.

License

Notifications You must be signed in to change notification settings

zacone/socket-holder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Socket Holder

Socket Holder is a socket management framework. Its core functions include socket management, business subscription, and service cluster broadcast.

socket-holder.jpg

中文

Quick Start

  1. Import Dependencies
<dependency>
    <groupId>com.isthisone</groupId>
    <artifactId>socket-holder-starter</artifactId>
    <version>1.1.0</version>
</dependency>
  1. Configure websocket information
#spring-boot3
spring:
  data:
    redis:
      host: 127.0.0.1
      port: 6379
      password: 123456

socket-holder:
  port: 8081
  path: '/ws'

or

#spring-boot2 or earlier
spring:
  redis:
    host: 127.0.0.1
    port: 6379
    password: 123456
socket-holder:
  port: 8081
  path: '/ws'
  1. Add @EnableSocketHolder annotation
@Configuration
@EnableSocketHolder
public class SocketHolderConfiguration {
}
  1. Create Websocket processing class
@RequiredArgsConstructor
@Component
@Slf4j
public class MyWebsocketHandler implements WebsocketHandler {

    private final StringSubscriberNotify stringSubscriberNotify;

    @Override
    public void process(HolderChannel channel, String text) {
        log.info("id-{},text-{}", channel.getId(), text);
        stringSubscriberNotify.subscribe("key", channel);
    }
}
  1. Use client to publish messages
@Component
@RequiredArgsConstructor
public class Tester() {

    private final SocketHolderClient socketHolderClient;

    public void test() {
        socketHolderClient.broadcast("Hello!");
    }
}
  1. Create redis broadcast class.
@RequiredArgsConstructor
@Component
@Slf4j
public class MyRedisBroadcastListener extends RedisBroadcastListener {

    private final StringSubscriberNotify stringSubscriberNotify;

    @Override
    public void listen(String topic, String msg) {
        log.info("topic-{},msg-{}", topic, msg);
        stringSubscriberNotify.notify("key", msg);
    }
}

About

Socket Holder is a socket management framework. Its core functions include socket management, business subscription, and service cluster broadcast.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages