public final class WebPubSubServiceClient extends Object
WebPubSubAsyncServiceClient
class documentation). To create an instance of this class, refer to the code
snippet below, and for more information about configuration options, refer to the JavaDoc for
WebPubSubClientBuilder
.
The Azure Web Pub Sub client instance must be connected to a
specific hub
that is represented by a non-null and non-empty String.
Within the Azure Web Pub Sub client, users may perform operations including:
everyone in the hub
,specific user
or
connection
,Removing a user
from all groups,Closing a connection
of a specific useruser
, a
connection
, or a group
,It is possible to connect to a specific group within a hub by calling
WebPubSubServiceClient.getGroup(String)
, which will return a WebPubSubGroup
. All operations performed on
this Azure Web Pub Sub group client will take into account the hub and group in which it exists.
Code Samples
WebPubSubServiceClient client = new WebPubSubClientBuilder() .connectionString("<Insert connection string from Azure Portal>") .buildClient();
Modifier and Type | Method and Description |
---|---|
boolean |
checkConnectionExists(String connectionId)
Check if a specific connection is connected to this hub.
|
com.azure.core.http.rest.Response<Boolean> |
checkConnectionExistsWithResponse(String connectionId,
com.azure.core.util.Context context)
Check if a specific connection is connected to this hub.
|
boolean |
checkGroupExists(String group)
Check if a particular group exists (i.e.
|
com.azure.core.http.rest.Response<Boolean> |
checkGroupExistsWithResponse(String group,
com.azure.core.util.Context context)
Check if a particular group exists (i.e.
|
boolean |
checkPermissionExists(WebPubSubPermission permission,
String connectionId,
String targetName)
Check if a connection has permission to the specified action.
|
com.azure.core.http.rest.Response<Boolean> |
checkPermissionExistsWithResponse(WebPubSubPermission permission,
String connectionId,
String targetName,
com.azure.core.util.Context context)
Check if a connection has permission to the specified action.
|
boolean |
checkUserExists(String userId)
Check if a particular user is connected to this hub.
|
com.azure.core.http.rest.Response<Boolean> |
checkUserExistsWithResponse(String userId,
com.azure.core.util.Context context)
Check if a particular user is connected to this hub.
|
void |
closeConnection(String connectionId)
Close a specific connection to this hub.
|
com.azure.core.http.rest.Response<Void> |
closeConnectionWithResponse(String connectionId,
String reason,
com.azure.core.util.Context context)
Close a specific connection to this hub.
|
WebPubSubAuthenticationToken |
getAuthenticationToken(GetAuthenticationTokenOptions options)
Creates an authentication token.
|
WebPubSubGroup |
getGroup(String group)
Creates a new synchronous
WebPubSubGroup for connecting to a specified
Azure Web Pub Sub group, which will also remain associated with the hub that was previously specified for the
calling client instance in its builder (set via WebPubSubClientBuilder.hub(String) . |
void |
grantPermission(WebPubSubPermission permission,
String connectionId)
Grant permission to the specified connection.
|
com.azure.core.http.rest.Response<Void> |
grantPermissionWithResponse(WebPubSubPermission permission,
String connectionId,
String targetName,
com.azure.core.util.Context context)
Grant permission to the specified connection.
|
void |
removeUserFromAllGroups(String userId)
Remove a specific user from all groups they are joined to.
|
com.azure.core.http.rest.Response<Void> |
removeUserFromAllGroupsWithResponse(String userId,
com.azure.core.util.Context context)
Remove a specific user from all groups they are joined to.
|
void |
revokePermission(WebPubSubPermission permission,
String connectionId)
Revoke permission for the specified connection.
|
com.azure.core.http.rest.Response<Void> |
revokePermissionWithResponse(WebPubSubPermission permission,
String connectionId,
String targetName,
com.azure.core.util.Context context)
Revoke permission for the specified connection.
|
void |
sendToAll(byte[] message)
Broadcast a binary message to all connections on this hub, excluding any connection IDs provided in the
excludedConnectionIds var-args (keeping in mind that it is valid to provide no excluded connection IDs). |
void |
sendToAll(byte[] message,
WebPubSubContentType contentType)
Broadcast a binary message to all connections on this hub, excluding any connection IDs provided in the
excludedConnectionIds var-args (keeping in mind that it is valid to provide no excluded connection IDs). |
void |
sendToAll(String message)
Broadcast a text message to all connections on this hub.
|
void |
sendToAll(String message,
WebPubSubContentType contentType)
Broadcast a text message to all connections on this hub.
|
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 on this hub, 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 on this hub, excluding any connection IDs provided in the
excludedConnectionIds list. |
void |
sendToConnection(String connectionId,
byte[] message)
Send a binary message to a specific connection
|
void |
sendToConnection(String connectionId,
byte[] message,
WebPubSubContentType contentType)
Send a binary message to a specific connection
|
void |
sendToConnection(String connectionId,
String message)
Send a message to a specific connection
|
void |
sendToConnection(String connectionId,
String message,
WebPubSubContentType contentType)
Send a message to a specific connection
|
com.azure.core.http.rest.Response<Void> |
sendToConnectionWithResponse(String connectionId,
byte[] message,
WebPubSubContentType contentType,
com.azure.core.util.Context context)
Send a binary message to a specific connection
|
com.azure.core.http.rest.Response<Void> |
sendToConnectionWithResponse(String connectionId,
String message,
WebPubSubContentType contentType,
com.azure.core.util.Context context)
Send a message to a specific connection
|
void |
sendToUser(String userId,
byte[] message)
Send a binary message to a specific user.
|
void |
sendToUser(String userId,
byte[] message,
WebPubSubContentType contentType)
Send a binary message to a specific user.
|
void |
sendToUser(String userId,
String message)
Send a text message to a specific user.
|
void |
sendToUser(String userId,
String message,
WebPubSubContentType contentType)
Send a text message to a specific user.
|
com.azure.core.http.rest.Response<Void> |
sendToUserWithResponse(String userId,
byte[] message,
WebPubSubContentType contentType,
com.azure.core.util.Context context)
Send a binary message to a specific user.
|
com.azure.core.http.rest.Response<Void> |
sendToUserWithResponse(String userId,
String message,
WebPubSubContentType contentType,
com.azure.core.util.Context context)
Send a text message to a specific user.
|
public WebPubSubGroup getGroup(String group)
WebPubSubGroup
for connecting to a specified
Azure Web Pub Sub group, which will also remain associated with the hub that was previously specified for the
calling client instance in its builder (set via WebPubSubClientBuilder.hub(String)
.group
- The name of the group.public WebPubSubAuthenticationToken getAuthenticationToken(GetAuthenticationTokenOptions options)
options
- Options to apply when creating the authentication token.public void sendToAll(String message)
Code Samples
To send a message to all users within the same hub, do the following:
client.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 hub, do the following:
client.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:
client.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:
client.sendToAllWithResponse( "Hello world!", WebPubSubContentType.TEXT_PLAIN, Arrays.asList("excluded-connection-id-1", "excluded-connection-id-2"), Context.NONE);
message
- The 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 sendToAll(byte[] message)
excludedConnectionIds
var-args (keeping in mind that it is valid to provide no excluded connection IDs).
Code Samples
To send a binary message to all users within the same hub, with no exclusions, do the following:
client.sendToAll("Hello world!".getBytes());
message
- The message to send.public void sendToAll(byte[] message, WebPubSubContentType contentType)
excludedConnectionIds
var-args (keeping in mind that it is valid to provide no excluded connection IDs).
Code Samples
To send a binary message to all users within the same hub, with no exclusions, do the following:
client.sendToAll("Hello world!".getBytes(), WebPubSubContentType.APPLICATION_OCTET_STREAM);
message
- The 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:
client.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:
client.sendToAllWithResponse( "Hello world!".getBytes(), WebPubSubContentType.APPLICATION_OCTET_STREAM, Arrays.asList("excluded-connection-id-1", "excluded-connection-id-2"), Context.NONE);
message
- The 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 sendToUser(String userId, String message)
userId
- User name to send to.message
- The message to send.public void sendToUser(String userId, String message, WebPubSubContentType contentType)
userId
- User name to send to.message
- The message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToUserWithResponse(String userId, String message, WebPubSubContentType contentType, com.azure.core.util.Context context)
userId
- User name to send to.message
- The message to send.contentType
- The content type of the message.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 sendToUser(String userId, byte[] message)
userId
- User name to send to.message
- The binary message to send.public void sendToUser(String userId, byte[] message, WebPubSubContentType contentType)
userId
- User name to send to.message
- The binary message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToUserWithResponse(String userId, byte[] message, WebPubSubContentType contentType, com.azure.core.util.Context context)
userId
- User name to send to.message
- The binary message to send.contentType
- The content type of the message.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 sendToConnection(String connectionId, String message)
connectionId
- Connection ID to send to.message
- The message to send.public void sendToConnection(String connectionId, String message, WebPubSubContentType contentType)
connectionId
- Connection ID to send to.message
- The message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToConnectionWithResponse(String connectionId, String message, WebPubSubContentType contentType, com.azure.core.util.Context context)
connectionId
- Connection ID to send to.message
- The message to send.contentType
- The content type of the message.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 sendToConnection(String connectionId, byte[] message)
connectionId
- Connection ID to send to.message
- The binary message to send.public void sendToConnection(String connectionId, byte[] message, WebPubSubContentType contentType)
connectionId
- Connection ID to send to.message
- The binary message to send.contentType
- The content type of the message.public com.azure.core.http.rest.Response<Void> sendToConnectionWithResponse(String connectionId, byte[] message, WebPubSubContentType contentType, com.azure.core.util.Context context)
connectionId
- Connection ID to send to.message
- The binary message to send.contentType
- The content type of the message.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 removeUserFromAllGroups(String userId)
userId
- The user ID to remove from all groups.public com.azure.core.http.rest.Response<Void> removeUserFromAllGroupsWithResponse(String userId, com.azure.core.util.Context context)
userId
- The user ID to remove from all groups.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 boolean checkUserExists(String userId)
userId
- The user name to check for.public com.azure.core.http.rest.Response<Boolean> checkUserExistsWithResponse(String userId, com.azure.core.util.Context context)
userId
- The user name to check for.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a Boolean value representing whether the user exists in this hub, as well as
status code and response headers representing the response from the service.public boolean checkGroupExists(String group)
group
- The group name to check for.public com.azure.core.http.rest.Response<Boolean> checkGroupExistsWithResponse(String group, com.azure.core.util.Context context)
group
- The group name to check for.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a Boolean value representing whether the group exists, as well as
status code and response headers representing the response from the service.public void closeConnection(String connectionId)
connectionId
- Connection ID to close.public com.azure.core.http.rest.Response<Void> closeConnectionWithResponse(String connectionId, String reason, com.azure.core.util.Context context)
connectionId
- Connection ID to close.reason
- The reason why the connection was closed.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 boolean checkConnectionExists(String connectionId)
connectionId
- Connection ID to check.public com.azure.core.http.rest.Response<Boolean> checkConnectionExistsWithResponse(String connectionId, com.azure.core.util.Context context)
connectionId
- Connection ID to check.context
- Additional context that is passed through the Http pipeline during the service call.Response
with a Boolean value representing whether the connection exists in this hub, as well
as status code and response headers representing the response from the service.public boolean checkPermissionExists(WebPubSubPermission permission, String connectionId, String targetName)
permission
- The permission to be checked against the given connection ID.connectionId
- Target connection Id.targetName
- Get the permission for the specific target. The meaning of the target depends on the specific
permission.public com.azure.core.http.rest.Response<Boolean> checkPermissionExistsWithResponse(WebPubSubPermission permission, String connectionId, String targetName, com.azure.core.util.Context context)
permission
- The permission to be checked against the given connection ID.connectionId
- Target connection Id.targetName
- Get the permission for the specific target. The meaning of the target depends on the specific
permission.context
- The context to associate with this operation.Response
with a Boolean value representing whether the connection
has the specified permission, as well as status code and response headers representing the response from
the service.public void grantPermission(WebPubSubPermission permission, String connectionId)
permission
- The permission to be granted to the given connection ID.connectionId
- Target connection ID.public com.azure.core.http.rest.Response<Void> grantPermissionWithResponse(WebPubSubPermission permission, String connectionId, String targetName, com.azure.core.util.Context context)
permission
- The permission to be granted to the given connection ID.connectionId
- Target connection ID.targetName
- The specific target that will have the permission granted.context
- The context to associate with the operation.Response
, enabling retrieval of the status code and response
headers from the service.public void revokePermission(WebPubSubPermission permission, String connectionId)
permission
- The permission to be revoked.connectionId
- Target connection ID.public com.azure.core.http.rest.Response<Void> revokePermissionWithResponse(WebPubSubPermission permission, String connectionId, String targetName, com.azure.core.util.Context context)
permission
- The permission to be revoked.connectionId
- Target connection ID.targetName
- Revoke the permission for the specific target.context
- The context to associate with this operation.Response
with a null value, but status code and response headers representing the response from
the service.Copyright © 2021 Microsoft Corporation. All rights reserved.