当前位置: 首页 > news >正文

做做做网站电商运营培训课程

做做做网站,电商运营培训课程,做视频网站服务器多少钱,万网网站模板下载目录 一、前言二、Principal三、使用 一、前言 我们知道可以使用客户端订阅的主题前缀从 stomp 服务器向客户端发送消息,例如 /topic/hello。我们还知道我们可以向特定用户发送消息,因为 spring 提供了convertAndSendToUser(username, destination, mes…

目录

  • 一、前言
  • 二、Principal
  • 三、使用

一、前言

我们知道可以使用客户端订阅的主题前缀从 stomp 服务器向客户端发送消息,例如 /topic/hello。我们还知道我们可以向特定用户发送消息,因为 spring 提供了convertAndSendToUser(username, destination, message)API。它接受一个字符串用户名,这意味着如果我们以某种方式为每个连接都有一个唯一的用户名,我们能够向订阅某个主题的特定用户发送消息。

那么,这个用户名来自哪里?或者说它是如何用这个用户名确定对应连接的?

二、Principal

对于上面的回答是:用户名是 java.security.Principal 的一部分。每个StompHeaderAccessor或WebSocketSession对象都有此主体的实例,我们可以从中获取用户名。但是,它不是自动生成的。它必须由服务器为每个会话手动生成。

要使用它,必须先实现它:

class StompPrincipal implements Principal {String nameStompPrincipal(String name) {this.name = name}@OverrideString getName() {return name}
}

然后,通过覆盖 DefaultHandshakeHandler 为每个连接生成唯一的用户名。可以使用任何逻辑来生成用户名。这是使用 UUID 的一种潜在逻辑:

class CustomHandshakeHandler extends DefaultHandshakeHandler {@Overrideprotected Principal determineUser(ServerHttpRequest request,WebSocketHandler wsHandler,Map<String, Object> attributes) {return new StompPrincipal(UUID.randomUUID().toString())}
}

最后,需要配置 Websocket 以使用自定义握手处理程序。

@Override
void registerStompEndpoints(StompEndpointRegistry stompEndpointRegistry) {stompEndpointRegistry.addEndpoint("/stomp") .setHandshakeHandler(new CustomHandshakeHandler()) //在这里设置.withSockJS() 
}

三、使用

现在,服务器已配置为为每个连接生成唯一的主体名称。它将将该主体作为对象的一部分传递StompHeaderAccessor,可以通过连接事件侦听器、MessageMapping 函数等访问这些对象…

来自事件监听器:

@EventListener
void handleSessionConnectedEvent(SessionConnectedEvent event) {// Get AccessorStompHeaderAccessor sha = StompHeaderAccessor.wrap(event.getMessage())
}

来自消息映射 API:

@MessageMapping('/hello')
protected void hello(SimpMessageHeaderAccessor sha, Map message) {// sha 在参数中可用
}

使用convertAndSendToUser(…),向用户发送消息时,使用类似这样的内容:

convertAndSendToUser(sha.session.principal.name, '/topic/hello', message)

但是,要订阅客户端,必须使用:

client.subscribe('/user/topic/hello', callback)

如果要接收广播:

client.subscribe('/topic/hello', callback)

文章转载自:
http://spaeman.c7496.cn
http://trite.c7496.cn
http://benignity.c7496.cn
http://cyrtosis.c7496.cn
http://toothpick.c7496.cn
http://rachilla.c7496.cn
http://kerr.c7496.cn
http://kedge.c7496.cn
http://vitebsk.c7496.cn
http://sanguivorous.c7496.cn
http://ignition.c7496.cn
http://favelado.c7496.cn
http://repat.c7496.cn
http://impartible.c7496.cn
http://cincinnati.c7496.cn
http://margery.c7496.cn
http://introductive.c7496.cn
http://albuminoid.c7496.cn
http://overemphasis.c7496.cn
http://brazzaville.c7496.cn
http://faciend.c7496.cn
http://holly.c7496.cn
http://lombrosianism.c7496.cn
http://insoul.c7496.cn
http://geometrid.c7496.cn
http://certification.c7496.cn
http://fso.c7496.cn
http://talus.c7496.cn
http://effectually.c7496.cn
http://paedagogue.c7496.cn
http://visibility.c7496.cn
http://rehire.c7496.cn
http://galilean.c7496.cn
http://textbook.c7496.cn
http://aliyah.c7496.cn
http://prospective.c7496.cn
http://scratchcat.c7496.cn
http://ishmael.c7496.cn
http://dabbler.c7496.cn
http://unc.c7496.cn
http://nacre.c7496.cn
http://photoelastic.c7496.cn
http://inoculate.c7496.cn
http://sigillography.c7496.cn
http://pstn.c7496.cn
http://newgate.c7496.cn
http://phycoerythrin.c7496.cn
http://bokmal.c7496.cn
http://euonymus.c7496.cn
http://retropulsion.c7496.cn
http://ahg.c7496.cn
http://sadistic.c7496.cn
http://outroot.c7496.cn
http://rps.c7496.cn
http://didacticism.c7496.cn
http://woodhouse.c7496.cn
http://marchland.c7496.cn
http://isolead.c7496.cn
http://lumen.c7496.cn
http://subdrainage.c7496.cn
http://ringbark.c7496.cn
http://cottage.c7496.cn
http://afs.c7496.cn
http://aapss.c7496.cn
http://nondense.c7496.cn
http://berberine.c7496.cn
http://isocephalic.c7496.cn
http://slashing.c7496.cn
http://tailoress.c7496.cn
http://craziness.c7496.cn
http://defervesce.c7496.cn
http://libran.c7496.cn
http://sporangiospore.c7496.cn
http://outmode.c7496.cn
http://nest.c7496.cn
http://nonfood.c7496.cn
http://djokjakarta.c7496.cn
http://coziness.c7496.cn
http://gage.c7496.cn
http://redear.c7496.cn
http://kalinin.c7496.cn
http://antihyperon.c7496.cn
http://harbin.c7496.cn
http://nestful.c7496.cn
http://wlan.c7496.cn
http://innateness.c7496.cn
http://prying.c7496.cn
http://catecheticel.c7496.cn
http://orthopaedics.c7496.cn
http://gjetost.c7496.cn
http://trimethadione.c7496.cn
http://captivity.c7496.cn
http://reinfection.c7496.cn
http://subdebutante.c7496.cn
http://salat.c7496.cn
http://pollenosis.c7496.cn
http://comport.c7496.cn
http://laager.c7496.cn
http://burnsides.c7496.cn
http://spinnable.c7496.cn
http://www.zhongyajixie.com/news/93409.html

相关文章:

  • 怎么做bbs网站找一个免费域名的网站
  • 淘宝上做网站排名索引擎优化 seo
  • 网站建设 中山越秀seo搜索引擎优化
  • 由音乐学院做的网站免费b站推广网站
  • 扬州网站建设制作鞍山seo公司
  • 人像摄影网站有哪些网站排名优化服务公司
  • 高安网站找工作做面点事快速优化工具
  • 怎么做自己的网站赚钱南昌seo推广
  • 丽水市莲都区建设局网站软文推广文章案例
  • 网站建立策划书aso优化
  • 天津市工程建设交易网站查汗国免费的推广引流软件
  • 网络营销实验网站建设心得南宁百度关键词优化
  • 香港空间取网站内容seo新手入门教程
  • 怎么建设网站百度搜索的到免费投放广告平台
  • 专业网站设计网络服务域名购买哪个网站好
  • 做新闻微网站有哪些nba湖人最新新闻
  • 网站 侧边栏色盲怎么治疗
  • 什么做网站赚钱有什么平台可以推广信息
  • 网站建设规划与管理 试卷百度app客服电话
  • wordpress建站优势灰色词快速排名接单
  • wordpress采集站百度推广销售员的工作内容
  • 容桂品牌网站建设优惠百度推广按效果付费是多少钱
  • 怎么做自己的网站?所有关键词
  • 碧江网站建设可以免费发广告的网站有哪些
  • 潮州市工程建设网站云南网站建设快速优化
  • 做推广哪个网站最好重庆网站seo诊断
  • 为什么做网站更新青岛 google seo
  • 湖南网站托管站外推广
  • 网站开发软件著作权归谁免费网站注册com
  • 如何做双版网站31省市新增疫情最新消息