Search code examples
spring-booturlchatspring-websocket

Generating unique URL postfix for users in spring boot websocket application


When a group chat application on web assigns a URL for a chat room (www.myGroupChat.com/xyroom34) the link can be shared to others to invite, server would have to ensure that each URL postfix (xyroom34) has never been generated/assigned as a group, to tackle this I have 2 questions to be solved:

  1. How to generate unique URLs (is building another microservice for this necessary?)
  2. In Spring websocket controller, Once the unique link is generated, how to map dynamic controller request mapping to clients with the same postfix, such that the resulting url is similar to www.myGroupChat.com/xyroom34.

Solution

  • 1: First problem can be minimized to generating unique UUIDs. Ample of solutions exist for this. Once such solution is using UUID class. If your requirement is to generate it based on some pattern then it would be a better idea to create a separate microservice for it. One performance optimization you can also do is to generate 10000 UUIDs in advance and keep it in the cache or DB.

    2: You can do that using PathVariables in spring.