메시징 서비스 는 동일한 경험의 서버가 토픽을 사용하여 실시간으로 서로 통신할 수 있도록 허용합니다(1초 미만).주제는 서버가 메시지를 보내고 받는 데 사용하는 개발자 정의 문자열(1–80자)입니다.
배달은 최선의 노력이지만 보장되지 않습니다. 배달 실패가 치명적이지 않도록 경험을 설계하십시오.
교차 서버 메시징은 서버 간에 더 자세하게 통신하는 방법을 살펴봅니다.
라이브 게임 서버에 임시 메시지를 게시하려면 Open Cloud API를 사용할 수 있습니다.
제한
이러한 제한은 변경될 수 있습니다.
<th>최대</th></tr></thead><tbody><tr><td><b>메시지 크기</b></td><td>1kB</td></tr><tr><td><b>게임 서버당 전송되는 메시지</b></td><td>분당 600 + 240 \* (이 게임 서버의 플레이어 수)</td></tr><tr><td><b>토픽당 받은 메시지</b></td><td>(40 + 80 \* 서버 수) 분당</td></tr><tr><td><b>전체 게임에 대한 메시지 수신</b></td><td>(400 + 200 \* 서버 수) 분당</td></tr><tr><td><b>게임 서버당 허용되는 구독</b></td><td>20 + 8 \* (이 게임 서버의 플레이어 수)</td></tr><tr><td><b>게임 서버당 구독 요청</b></td><td>분당 240 요청</td></tr></tbody>
제한 |
---|
요약
메서드
메시지가 토픽에 푸시될 때마다 제공된 콜백을 호출합니다.
지정된 주제를 듣기 시작합니다.
속성
메서드
PublishAsync
이 함수는 제공된 메시지를 토픽의 모든 구독자에게 보내 등록된 콜백을 트리거하고, 이를 호출합니다.
백엔드에서 메시지를 받을 때까지 생성됩니다.
매개 변수
메시지가 발송되는 위치를 결정합니다.
메시지에 포함할 데이터.
반환
SubscribeAsync
이 함수는 지정된 주제를 듣기 시작하기 위한 콜백을 등록합니다.콜백은 토픽이 메시지를 받을 때 호출됩니다.동일한 주제에 대해 여러 번 호출할 수 있습니다.
콜백
콜백은 단일 인수로 호출되며 다음 항목이 포함된 테이블입니다.
<th>요약</th></tr></thead><tbody><tr><td><b>데이터</b></td><td>개발자가 페이로드를 제공했음</td></tr><tr><td><b>보냄</b></td><td>메시지가 전송된 시간(초) Unix 시간 in seconds at which the message was sent</td></tr></tbody>
필드 |
---|
구독이 올바르게 등록될 때까지 생성되며 연결 개체를 반환합니다.
구독을 취소하려면 반환된 개체에서 Disconnect()를 호출하십시오.한 번 호출되면 콜백은 결코 호출되어서는 안됩니다.연결이 포함된 스크립트를 처리하면 기본 연결도 취소됩니다.
또한 제공된 메시지를 토픽의 모든 구독자에게 보내 등록된 콜백을 트리거하는 MessagingService:PublishAsync()를 참조하십시오.
매개 변수
반환
토픽에서 구독을 취소할 수 있는 연결.
코드 샘플
This example demonstrates how to use MessagingService:SubscribeAsync() to listen to a topic for cross-server chat within a game universe.
When a player joins, the example subscribes to the topic player-<player.UserId>. When a message is sent with this topic, the connected callback executes and prints Received message for <player.Name">. It also disconnects the connection when the player's ancestry changes.
In order for this to work as expected it must be placed in a server Script.
local MessagingService = game:GetService("MessagingService")
local Players = game:GetService("Players")
local function onPlayerAdded(player)
--subscribe to the topic
local topic = "player-" .. player.UserId
local connection = MessagingService:SubscribeAsync(topic, function(message)
print("Received message for", player.Name, message.Data)
end)
player.AncestryChanged:Connect(function()
-- unsubscribe from the topic
connection:Disconnect()
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)