public abstract class SessionService
extends java.lang.Object
implements java.io.Serializable
Override this class and the method initializeSessionProperties(JCSMPProperties)
with
your specific properties, including all those related to authentication.
The connector will call the method only once per session created, so you can perform relatively heavy operations in that method (e.g. connect to a store or vault to retrieve credentials).
There are some default properties that are set by default and can be overridden in this provider, that are relevant for the writer connector, and not used in the case of the read connector (since they are not necessary for reading):
The connector overrides other properties, regardless of what this provider sends to the connector. Those properties are the following. Again, these properties are only relevant for the write connector.
SolaceIO.Write.withWriterType(SolaceIO.WriterType)
and SolaceIO.Write.withSubmissionMode(SolaceIO.SubmissionMode)
.
The method will always run in a worker thread or task, and not in the driver program. If you need to access any resource to set the properties, you need to make sure that the worker has the network connectivity required for that, and that any credential or configuration is passed to the provider through the constructor.
The connector ensures that no two threads will be calling that method at the same time, so you don't have to take any specific precautions to avoid race conditions.
For basic authentication, use BasicAuthJcsmpSessionService
and BasicAuthJcsmpSessionServiceFactory
.
For other situations, you need to extend this class. For instance:
public class MySessionService extends SessionService {
private final String authToken;
public MySessionService(String token) {
this.oauthToken = token;
...
}
{@literal }@Override
public JCSMPProperties initializeSessionProperties(JCSMPProperties baseProps) {
baseProps.setProperty(JCSMPProperties.AUTHENTICATION_SCHEME, JCSMPProperties.AUTHENTICATION_SCHEME_OAUTH2);
baseProps.setProperty(JCSMPProperties.OAUTH2_ACCESS_TOKEN, authToken);
return props;
}
{@literal }@Override
public void connect() {
...
}
...
}
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_VPN_NAME |
Constructor and Description |
---|
SessionService() |
Modifier and Type | Method and Description |
---|---|
abstract void |
close()
Gracefully closes the connection to the service.
|
abstract void |
connect()
Establishes a connection to the service.
|
abstract MessageReceiver |
createReceiver()
Creates a MessageReceiver object for receiving messages from Solace.
|
abstract JCSMPProperties |
initializeSessionProperties(JCSMPProperties baseProperties)
Override this method and provide your specific properties, including all those related to
authentication, and possibly others too.
|
JCSMPProperties |
initializeWriteSessionProperties(SolaceIO.SubmissionMode mode)
This method will be called by the write connector when a new session is started.
|
abstract boolean |
isClosed()
Checks whether the connection to the service is currently closed.
|
public static final java.lang.String DEFAULT_VPN_NAME
public abstract void connect()
public abstract void close()
public abstract boolean isClosed()
public abstract MessageReceiver createReceiver()
public abstract JCSMPProperties initializeSessionProperties(JCSMPProperties baseProperties)
You should add your properties to the parameter baseProperties, and return the result.
The method will be used whenever the session needs to be created or refreshed. If you are setting credentials with expiration, just make sure that the latest available credentials (e.g. renewed token) are set when the method is called.
For a list of all the properties that can be set, please check the following link:
public final JCSMPProperties initializeWriteSessionProperties(SolaceIO.SubmissionMode mode)
This call will happen in the worker, so you need to make sure that the worker has access to the resources you need to set the properties.
The call will happen only once per session initialization. Typically, that will be when the worker and the client are created. But if for any reason the session is lost (e.g. expired auth token), this method will be called again.