Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9ac9135c
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ac9135c
编写于
3月 18, 2016
作者:
R
Rossen Stoyanchev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update reference on StompClient
Issue: SPR-13664
上级
c5200978
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
34 addition
and
26 deletion
+34
-26
src/asciidoc/web-websocket.adoc
src/asciidoc/web-websocket.adoc
+34
-26
未找到文件。
src/asciidoc/web-websocket.adoc
浏览文件 @
9ac9135c
...
...
@@ -1884,41 +1884,40 @@ to access information about the message.
[[
websocket
-
stomp
-
client
]]
===
STOMP
Client
Spring
provides
STOMP
/
WebSocket
client
and
STOMP
/
TCP
client
support
with
the
following
built
-
in
choices
(
other
libraries
can
be
adapted
):
Spring
provides
a
STOMP
over
WebSocket
client
and
a
STOMP
over
TCP
client
.
*
`
WebSocketStompClient
`
built
on
the
Spring
WebSocket
API
with
support
for
standard
JSR
-
356
WebSocket
,
Jetty
9
,
as
well
as
SockJS
for
HTTP
-
based
WebSocket
emulation
(
see
<<
websocket
-
fallback
-
sockjs
-
client
>>).
*
`
Reactor11TcpStompClient
`
built
on
`
NettyTcpClient
`
from
the
reactor
-
net
project
.
To
begin
,
create
and
configure
the
client
:
To
begin
create
and
configure
`
WebSocketStompClient
`:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
----
WebSocketClient
transpor
t
=
new
StandardWebSocketClient
();
WebSocketStompClient
stompClient
=
new
WebSocketStompClient
(
transpor
t
);
WebSocketClient
webSocketClien
t
=
new
StandardWebSocketClient
();
WebSocketStompClient
stompClient
=
new
WebSocketStompClient
(
webSocketClien
t
);
stompClient
.
setMessageConverter
(
new
StringMessageConverter
());
stompClient
.
setTaskScheduler
(
taskScheduler
);
//
for
heartbeats
,
receipts
stompClient
.
setTaskScheduler
(
taskScheduler
);
//
for
heartbeats
----
Then
connect
to
the
WebSocket
and
provide
a
handler
for
the
STOMP
session
:
In
the
above
example
`
StandardWebSocketClient
`
could
be
replaced
with
`
SockJsClient
`
since
that
is
also
an
implementation
of
`
WebSocketClient
`.
The
`
SockJsClient
`
can
use
WebSocket
or
HTTP
-
based
transport
as
a
fallback
.
For
more
details
see
<<
websocket
-
fallback
-
sockjs
-
client
>>.
Next
establish
a
connection
and
provide
a
handler
for
the
STOMP
session
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
----
String
url
=
"ws://127.0.0.1:8080/endpoint"
;
StompSessionHandler
handler
=
...
;
stompClient
.
connect
(
url
,
h
andler
);
StompSessionHandler
sessionHandler
=
new
MyStompSessionHandler
()
;
stompClient
.
connect
(
url
,
sessionH
andler
);
----
When
the
session
is
ready
for
use
,
the
handler
is
notified
:
When
the
session
is
ready
for
use
the
handler
is
notified
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
----
public
class
MySessionHandler
extends
StompSessionHandlerAdapter
{
public
class
MyS
tompS
essionHandler
extends
StompSessionHandlerAdapter
{
@
Override
public
void
afterConnected
(
StompSession
session
,
StompHeaders
connectedHeaders
)
{
...
...
@@ -1927,7 +1926,8 @@ public class MySessionHandler extends StompSessionHandlerAdapter {
}
----
Send
any
Object
as
the
payload
and
it
will
be
serialized
with
a
`
MessageConverter
`:
Once
the
session
is
established
any
payload
can
be
sent
and
that
will
be
serialized
with
the
configured
`
MessageConverter
`:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
...
...
@@ -1935,10 +1935,10 @@ Send any Object as the payload and it will be serialized with a `MessageConverte
session
.
send
(
"/topic/foo"
,
"payload"
);
----
The
subscribe
methods
take
a
`
StompFrameHandler
`
for
messages
on
the
subscription
and
return
a
`
Subscription
`
handle
for
unsubscribing
.
For
each
received
message
,
the
handler
must
help
to
select
the
target
type
and
then
handle
the
deserialized
payload
:
You
can
also
subscribe
to
destinations
.
The
`
subscribe
`
methods
require
a
handler
for
messages
on
the
subscription
and
return
a
`
Subscription
`
handle
that
can
be
used
to
unsubscribe
.
For
each
received
message
the
handler
can
specify
the
target
Object
type
the
payload
should
be
deserialized
to
:
[
source
,
java
,
indent
=
0
]
[
subs
=
"verbatim,quotes"
]
...
...
@@ -1958,11 +1958,19 @@ session.subscribe("/topic/foo", new StompFrameHandler() {
});
----
STOMP
supports
heartbeats
.
To
use
this
feature
simply
configure
the
`
WebSocketStompClient
`
with
a
`
TaskScheduler
`
and
if
desired
customize
the
default
heartbeat
intervals
(
10
,
10
seconds
respectively
by
default
)
for
write
inactivity
which
causes
a
heartbeat
to
be
sent
and
for
read
inactivity
which
closes
the
connection
.
To
enable
STOMP
heartbeat
configure
`
WebSocketStompClient
`
with
a
`
TaskScheduler
`
and
optionally
customize
the
heartbeat
intervals
,
10
seconds
for
write
inactivity
which
causes
a
heartbeat
to
be
sent
and
10
seconds
for
read
inactivity
which
closes
the
connection
.
[
NOTE
]
====
When
using
`
WebSocketStompClient
`
for
performance
tests
to
simulate
thousands
of
clients
from
the
same
machine
consider
turning
off
heartbeats
since
each
connection
schedules
its
own
heartbeat
tasks
and
that
's not optimized for a
a large number of clients running on the same machine.
====
The STOMP protocol also supports receipts where the client must add a "receipt"
header to which the server responds with a RECEIPT frame after the send or
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录