public final class WebPubSubGroup extends Object
Sync client for interacting with a specific Azure Web Pub Sub group, contained within an Azure Web Pub Sub hub.
An instance of this group client is able to be created by calling
WebPubSubServiceClient.getGroup(String)
on a WebPubSubServiceClient
instance. All
operations performed on an instance of a group client takes into account the specified group name, as well as the
name of the hub specified when instantiating the WebPubSubServiceClient
via the
WebPubSubClientBuilder
. This is demonstrated in the code below:
WebPubSubServiceClient client = new WebPubSubClientBuilder() .connectionString("<Insert connection string from Azure Portal>") .hub("chat-portal") .buildClient(); WebPubSubGroup adminGroup = client.getGroup("admins");
Modifier and Type | Method and Description |
---|---|
void |
addConnection(String connectionId)
Add a specific connection to this group.
|
com.azure.core.http.rest.Response<Void> |
addConnectionWithResponse(String connectionId,
com.azure.core.util.Context context)
Add a specific connection to this group.
|
void |
addUser(String userId)
Add a user to this group.
|
com.azure.core.http.rest.Response<Void> |
addUserWithResponse(String userId,
com.azure.core.util.Context context)
Add a user to this group.
|
void |
removeConnection(String connectionId)
Remove a specific connection from this group.
|
com.azure.core.http.rest.Response<Void> |
removeConnectionWithResponse(String connectionId,
com.azure.core.util.Context context)
Remove a specific connection from this group.
|
void |
removeUser(String userId)
Remove a user from this group.
|
com.azure.core.http.rest.Response<Void> |
removeUserWithResponse(String userId,
com.azure.core.util.Context context)
Remove a user from this group.
|
void |
sendToAll(byte[] message)
Broadcast a binary message to all connections in this group.
|
void |
sendToAll(byte[] message,
WebPubSubContentType contentType)
Broadcast a binary message to all connections in this group.
|
void |
sendToAll(String message)
Broadcast a text message to all connections in this group.
|
void |
sendToAll(String message,
WebPubSubContentType contentType)
Broadcast a text message to all connections in this group.
|
com.azure.core.http.rest.Response<Void> |
sendToAllWithResponse(byte[] message,
WebPubSubContentType contentType,
Iterable<String> excludedConnectionIds,
com.azure.core.util.Context context)
Broadcast a binary message to all connections in this group, excluding any connection IDs provided in the
excludedConnectionIds list. |
com.azure.core.http.rest.Response<Void> |
sendToAllWithResponse(String message,
WebPubSubContentType contentType,
Iterable<String> excludedConnectionIds,
com.azure.core.util.Context context)
Broadcast a text message to all connections in this group, excluding any connection IDs provided in the
excludedConnectionIds list. |
public void sendToAll(String message)
Code Samples
To send a message to all users within the same group, with no exclusions, do the following:
adminGroup.sendToAll("Hello world!");
message
- The message to send.public void sendToAll(String message, WebPubSubContentType contentType)
Code Samples
To send a message to all users within the same group, with no exclusions, do the following:
adminGroup.sendToAll("Hello world!", WebPubSubContentType.TEXT_PLAIN);
message
- The message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToAllWithResponse(String message, WebPubSubContentType contentType, Iterable<String> excludedConnectionIds, com.azure.core.util.Context context)
excludedConnectionIds
list.
Code Samples
To send a message to all users within the same hub, with no exclusions, do the following:
adminGroup.sendToAllWithResponse("Hello world!", WebPubSubContentType.TEXT_PLAIN, Collections.emptyList(), Context.NONE);
To send a message to all users within the same hub, with one or more connection IDs excluded, simply add the excluded connection IDs to a List and pass that in as the third argument:
List<String> excludedConnectionIds = getExcludedConnectionIds(); adminGroup.sendToAllWithResponse("Hello world!", WebPubSubContentType.TEXT_PLAIN, excludedConnectionIds, Context.NONE);
message
- The message to send.contentType
- The content type of the message.excludedConnectionIds
- An optional var-args of connection IDs to not broadcast the message to.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.public void sendToAll(byte[] message)
Code Samples
To send a binary message to all users within the same hub, with no exclusions, do the following:
adminGroup.sendToAll("Hello world!".getBytes());
message
- The binary message to send.public void sendToAll(byte[] message, WebPubSubContentType contentType)
Code Samples
To send a binary message to all users within the same hub, with no exclusions, do the following:
adminGroup.sendToAll("Hello world!".getBytes(), WebPubSubContentType.APPLICATION_OCTET_STREAM);
message
- The binary message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToAllWithResponse(byte[] message, WebPubSubContentType contentType, Iterable<String> excludedConnectionIds, com.azure.core.util.Context context)
excludedConnectionIds
list.
Code Samples
To send a binary message to all users within the same hub, with no exclusions, do the following:
adminGroup.sendToAllWithResponse("Hello world!".getBytes(), WebPubSubContentType.APPLICATION_OCTET_STREAM, Collections.emptyList(), Context.NONE);
To send a binary message to all users within the same hub, with one or more connection IDs excluded, simply add the excluded connection IDs to the end of the method call as var-args:
List<String> excludedConnectionIds = getExcludedConnectionIds(); adminGroup.sendToAllWithResponse("Hello world!".getBytes(), WebPubSubContentType.APPLICATION_OCTET_STREAM, excludedConnectionIds, Context.NONE);
message
- The binary message to send.contentType
- The content type of the message.excludedConnectionIds
- An optional list of connection IDs to not broadcast the message to.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.public void addUser(String userId)
userId
- The user name to addpublic com.azure.core.http.rest.Response<Void> addUserWithResponse(String userId, com.azure.core.util.Context context)
userId
- The user name to add.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.public void removeUser(String userId)
userId
- The user name to removepublic com.azure.core.http.rest.Response<Void> removeUserWithResponse(String userId, com.azure.core.util.Context context)
userId
- The user name to removecontext
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.public void addConnection(String connectionId)
connectionId
- The connection id to add to this group.public com.azure.core.http.rest.Response<Void> addConnectionWithResponse(String connectionId, com.azure.core.util.Context context)
connectionId
- The connection id to add to this group.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.public void removeConnection(String connectionId)
connectionId
- The connection id to remove from this group.public com.azure.core.http.rest.Response<Void> removeConnectionWithResponse(String connectionId, com.azure.core.util.Context context)
connectionId
- The connection id to remove from this group.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a null value, but status code and response headers representing the response from
the service.Copyright © 2021 Microsoft Corporation. All rights reserved.