Skip to content

flexicore-boot-starter-websocket handles plugins that uses the spring-boot-starter-websocket (adds WS support for plugins)

License

Notifications You must be signed in to change notification settings

wizzdi/flexicore-boot-starter-websocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlexiCore Boot Starter Websocket Build StatusMaven Central

For comprehensive information about FlexiCore Boot Starter Websocket please visit our site.

What it does?

FlexiCore Boot Starter Websocket is a FlexiCore Module that enables Java's Server Endpoint inside FlexiCore Plugins.

How to use?

Add the flexicore-boot-starter-websocket dependency using the latest version available from maven central:

		<dependency>
            <groupId>com.wizzdi</groupId>
            <artifactId>flexicore-boot-starter-websocket</artifactId>
            <version>LATEST</version>
        </dependency>

Simply annotate your application class or your configuration class with

@EnableFlexiCoreWebSocketPlugins

Example

your application class:

@EnableFlexiCorePlugins  
@EnableFlexiCoreWebSocketPlugins
@SpringBootApplication  
public class App {  
  
   public static void main(String[] args) {  
  
      SpringApplication app = new SpringApplication(App.class);  
  app.addListeners(new ApplicationPidFileWriter());  
  ConfigurableApplicationContext context=app.run(args);  
  
  }
}

a Websocket Server Endpoint inside a plugin:

@ServerEndpoint(value = "/wsTest/{authenticationKey}", encoders = {WSEncoder.class}, decoders = {WSDecoder.class})  
@PluginInfo(version = 1)  
@Extension  
@Component  
public class TestWS implements Plugin {  
  
   private static final Logger logger=LoggerFactory.getLogger(TestWS.class);  
  
  @Autowired  
  private ApplicationEventPublisher eventReceivedContainerEvent;  
  
  @OnMessage  
  public void onMessage(WSEvent message, Session session) {  
      logger.info("received message " + message);  
  eventReceivedContainerEvent.publishEvent(new EventReceivedContainer()  
            .setWsEvent(message).setSession(session));  
  }  
  
   @OnOpen  
  public void open(@PathParam("authenticationKey") String authenticationKey,  
  Session session) {  
      logger.info("Opening:" + session.getId());  
 try {  
         session.getBasicRemote().sendObject(new TestMessage().setTest("test: " + session.getId()));  
  }  
      catch (Exception e){  
         logger.error("failed sending hello message");  
  }  
      UiEventSender.registerUISession(session);  
  }  
  
   @OnClose  
  public void close(@PathParam("authenticationKey") String authenticationKey,  
  CloseReason c, Session session) {  
      logger.info("Closing:" + session.getId());  
  UiEventSender.unregisterSession(session);  
  }  
  
}

Main Dependencies

FlexiCore Boot

FlexiCore Boot Starter Web

Spring Boot Starter Websocket

About

flexicore-boot-starter-websocket handles plugins that uses the spring-boot-starter-websocket (adds WS support for plugins)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages