### Build Solace Spring Boot Locally with Maven
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/README.md
This command clones the Solace Spring Boot repository and builds all artifacts locally using Maven. It requires Git and Maven to be installed. The `mvn package` command compiles, tests, and packages the code, while `mvn install` also installs the artifacts into the local Maven repository.
```shell
git clone https://github.com/SolaceProducts/solace-spring-boot.git
cd solace-spring-boot
mvn package # or mvn install to install them locally
```
--------------------------------
### Generate Root CA Key and Certificate
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/resources/certs/README.txt
Generates a private key and a self-signed certificate for the Root Certificate Authority (CA). The certificate is valid for 20 years. This CA will be used to sign certificates for other components.
```bash
mkdir rootCA
openssl genrsa -out ./rootCA/rootCA.key 4096
openssl req -x509 -new -nodes -key ./rootCA/rootCA.key -sha256 -days 7300 -out ./rootCA/rootCA.crt \
-subj "/C=CA/ST=Ontario/L=Kanata/O=Solace Systems/CN=Root CA"
cat ./rootCA/rootCA.key ./rootCA/rootCA.crt > ./rootCA/rootCA.pem
openssl x509 -in ./rootCA/rootCA.crt -text -noout
```
--------------------------------
### Generate Solace Client Certificate and Truststore
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/resources/certs/README.txt
Generates a private key and CSR for the Solace client, signs it with the Root CA, and creates a PEM file. It also generates a DER format of the Root CA certificate and imports it into a client truststore (PKCS12 format). Finally, it creates a client keystore (JKS format) containing the client's private key and certificate.
```bash
mkdir client
openssl genrsa -out ./client/client.key 2048
openssl req -new -key ./client/client.key -out ./client/client.csr \
-subj "/C=CA/ST=Ontario/L=Kanata/O=Solace Systems/CN=solclient"
openssl x509 -req -in ./client/client.csr -CA ./rootCA/rootCA.crt -CAkey ./rootCA/rootCA.key -CAcreateserial \
-out ./client/client.crt -days 7300 -sha256
cat ./client/client.key ./client/client.crt > ./client/client.pem
openssl x509 -in ./client/client.crt -text -noout
openssl x509 -outform der -in ./rootCA/rootCA.pem -out ./rootCA/rootCA.der
keytool -import -trustcacerts -alias root_ca -file ./rootCA/rootCA.der -keystore ./client/client-truststore.p12 -storepass changeMe123 -noprompt
keytool -v -list -keystore ./client/client-truststore.p12 -storepass changeMe123openssl pkcs12 -export -in ./client/client.pem -inkey ./client/client.key -name client -out ./client/client.p12 -passout pass:changeMe123
keytool -importkeystore -srckeystore ./client/client.p12 -srcstoretype PKCS12 -destkeystore ./client/client-keystore.jks -deststoretype JKS -srcstorepass changeMe123 -deststorepass changeMe123
```
--------------------------------
### Generate Keycloak Server Certificate
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/resources/certs/README.txt
Generates a private key, a CSR, and signs it with the Root CA to create a certificate for the Keycloak server. It also creates a PEM file containing the key and certificate, and verifies the generated certificate. This process is similar to the Solace broker certificate generation but uses a specific configuration file for Keycloak.
```bash
mkdir keycloak
openssl genrsa -out ./keycloak/keycloak.key 2048
openssl req -new -key ./keycloak/keycloak.key -out ./keycloak/keycloak.csr -config ./keycloak_san.conf
openssl x509 -req -in ./keycloak/keycloak.csr -CA ./rootCA/rootCA.crt -CAkey ./rootCA/rootCA.key -CAcreateserial \
-out ./keycloak/keycloak.crt -days 7300 -sha256 -extensions req_ext -extfile ./keycloak_san.conf
cat ./keycloak/keycloak.key ./keycloak/keycloak.crt > ./keycloak/keycloak.pem
openssl x509 -in ./keycloak/keycloak.crt -text -noout
```
--------------------------------
### Generate Solace Broker Certificate
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-autoconfigure/solace-java-spring-boot-autoconfigure/src/test/resources/certs/README.txt
Creates a private key, a Certificate Signing Request (CSR), and signs it with the Root CA to generate a certificate for the Solace PubSub+ broker. It also creates a PEM file containing the key and certificate, and verifies the generated certificate.
```bash
mkdir broker
openssl genrsa -out ./broker/solbroker.key 2048
openssl req -new -key ./broker/solbroker.key -out ./broker/solbroker.csr -config ./solbroker_san.conf
openssl x509 -req -in ./broker/solbroker.csr -CA ./rootCA/rootCA.crt -CAkey ./rootCA/rootCA.key -CAcreateserial \
-out ./broker/solbroker.crt -days 7300 -sha256 -extensions req_ext -extfile ./solbroker_san.conf
cat ./broker/solbroker.key ./broker/solbroker.crt > ./broker/solbroker.pem
openssl x509 -in ./broker/solbroker.crt -text -noout
```
--------------------------------
### Default Solace OAuth2 Session Event Handler Implementation
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This Java code snippet refers to the `DefaultSolaceOAuth2SessionEventHandler` class, which offers a default implementation for the `SolaceOAuth2SessionEventHandler` interface. It can be used as a starting point for developing custom token refresh handling.
```java
// com.solacesystems.jcsmp.DefaultSolaceOAuth2SessionEventHandler
```
--------------------------------
### Perform Release with Maven
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/README.md
This command sequence uses Maven's release plugin to prepare and perform a release. It automates the process of tagging a release, building it, and deploying it to a repository. Ensure your Maven settings are configured for release operations.
```shell
mvn -B release:prepare release:perform
```
--------------------------------
### Run Solace JMS Sample App with Maven
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-samples/solace-jms-sample-app/README.md
This command demonstrates how to run the Solace JMS sample application from the project root directory using Maven. It assumes you are in the 'solace-spring-boot-samples/solace-jms-sample-app' directory. The sample automatically provisions the necessary queue on the message broker.
```shell
cd solace-spring-boot-samples/solace-jms-sample-app
mvn spring-boot:run
```
--------------------------------
### Manage Spring Boot BOM Version with Solace Starters (XML)
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This XML snippet demonstrates how to import a specific version of the Solace Spring Boot BOM into your Maven project's dependency management. This ensures consistent versions of Solace starters compatible with your chosen Spring Boot version. It requires Maven as a build tool.
```xml
com.solace.spring.boot
solace-spring-boot-bom
2.5.0
pom
import
```
--------------------------------
### Include Solace Spring Boot BOM with Maven
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-bom/README.md
Demonstrates how to include the Solace Spring Boot BOM in a Maven project's dependency management. This allows for version-less inclusion of Solace Spring Boot starters.
```xml
com.solace.spring.boot
solace-spring-boot-bom
2.5.0
pom
import
com.solace.spring.boot
solace-spring-boot-starter
```
--------------------------------
### Add OAuth2 Client Dependency to Gradle
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This snippet shows how to add the Spring Boot OAuth2 Client starter dependency to your `build.gradle` file. This dependency is necessary for enabling OAuth2 client capabilities in your Spring Boot application.
```groovy
compile("org.springframework.boot:spring-boot-starter-oauth2-client")
```
--------------------------------
### Add Solace Spring Boot Starter Dependency (Maven)
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
Add the Solace Java API and auto-configuration starter to your Maven project's dependencies. This allows Maven to manage the Solace integration for your Spring Boot application.
```xml
com.solace.spring.boot
solace-java-spring-boot-starter
5.2.0
```
--------------------------------
### Include Solace Spring Boot BOM with Gradle
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-bom/README.md
Shows how to integrate the Solace Spring Boot BOM into a Gradle project using the 'platform' dependency configuration. This enables version-less dependency declarations for Solace starters.
```groovy
dependencies {
implementation(platform("com.solace.spring.boot:solace-spring-boot-bom:2.5.0"))
implementation("com.solace.spring.boot:solace-spring-boot-starter")
}
```
--------------------------------
### Add OAuth2 Client Dependency to Maven
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This snippet demonstrates how to add the Spring Boot OAuth2 Client starter dependency to your `pom.xml` file. This dependency is required for integrating OAuth2 client functionality into your Spring Boot project.
```xml
org.springframework.boot
spring-boot-starter-oauth2-client
```
--------------------------------
### Add Solace Spring Boot Starter Dependency (Gradle)
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
Include the Solace Java API and auto-configuration starter in your Gradle project. This dependency enables Spring Boot to automatically configure Solace components.
```groovy
// Solace Java API & auto-configuration
compile("com.solace.spring.boot:solace-java-spring-boot-starter:5.2.0")
```
--------------------------------
### Add OAuth2 Dependency for Spring Boot
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This XML snippet shows how to add the necessary Spring Boot starter OAuth2 client dependency to your Maven project. This dependency enables Spring Security's OAuth2 client capabilities, which are crucial for configuring secure connections.
```xml
org.springframework.boot
spring-boot-starter-oauth2-client
```
--------------------------------
### Configure Solace API Logging in Spring Boot
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-samples/solace-jms-sample-app/README.md
This configuration snippet shows how to enable and set the logging level for the Solace API within a Spring Boot application. It is added to the 'application.properties' file. This helps in troubleshooting by providing visibility into Solace-specific operations.
```properties
# Solace logging example:
logging.level.com.solacesystems=INFO
```
--------------------------------
### Spring Boot JMS Demo with Solace ConnectionFactory
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This Java code demonstrates a Spring Boot application that uses Solace JMS. It includes a message producer that sends messages to a queue and a message handler that listens for and processes incoming messages. It also shows how to configure a custom JmsListenerContainerFactory with an error handler.
```java
package jmsdemo;
import jakarta.jms.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.ErrorHandler;
@SpringBootApplication
public class JmsApplication {
public static void main(String[] args) {
SpringApplication.run(JmsApplication.class, args);
}
@Service
static class MessageProducer implements CommandLineRunner {
@Autowired
private JmsTemplate jmsTemplate;
@Value("${solace.jms.demoQueueName}")
private String queueName;
public void run(String... args) throws Exception {
String message = "Hello World from JMS";
System.out.println("Sending: " + message);
jmsTemplate.convertAndSend(queueName, message);
}
}
@Component
static class MessageHandler {
@JmsListener(destination = "${solace.jms.demoQueueName}", containerFactory = "cFactory", concurrency = "2")
public void processMessage(Message> msg) {
MessageHeaders headers = msg.getHeaders();
System.out.println("Received message:");
System.out.println(" UUID: " + headers.getId());
System.out.println(" Timestamp: " + headers.getTimestamp());
System.out.println(" Payload: " + msg.getPayload());
}
}
@EnableJms
@Configuration
static class JmsConfig {
@Bean
public DefaultJmsListenerContainerFactory cFactory(
ConnectionFactory connectionFactory,
JmsErrorHandler errorHandler) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setErrorHandler(errorHandler);
return factory;
}
@Service
public class JmsErrorHandler implements ErrorHandler {
public void handleError(Throwable t) {
System.err.println("JMS Error: " + t.getMessage());
t.printStackTrace();
}
}
}
}
```
--------------------------------
### Enable Web Security in Spring Boot Application
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This Java code snippet shows how to enable Spring Security's web security features by adding the `@EnableWebSecurity` annotation to your main Spring Boot application class. This is a prerequisite for configuring OAuth2 authentication.
```java
@SpringBootApplication
@EnableWebSecurity
public class DemoApplication {
}
```
--------------------------------
### Spring Boot Application with Solace JCSMP Session
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
Demonstrates a Spring Boot application that uses `SpringJCSMPFactory` to create a JCSMP session, set up a consumer and producer, send a message, and consume it. It requires the Solace Java API and Spring Boot dependencies.
```java
package demo;
import com.solacesystems.jcsmp.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Component;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@SpringBootApplication
public class SolaceJavaApplication {
public static void main(String[] args) {
SpringApplication.run(SolaceJavaApplication.class, args);
}
@Component
static class MessageRunner implements CommandLineRunner {
@Autowired
private SpringJCSMPFactory solaceFactory;
// Optional: access properties directly for customization
@Autowired(required = false)
private JCSMPProperties jcsmpProperties;
private final CountDownLatch latch = new CountDownLatch(1);
public void run(String... args) throws Exception {
// Create session from auto-configured factory
final JCSMPSession session = solaceFactory.createSession();
// Create topic
final Topic topic = JCSMPFactory.onlyInstance().createTopic("tutorial/topic");
// Set up consumer with message listener
XMLMessageConsumer consumer = session.getMessageConsumer(new XMLMessageListener() {
@Override
public void onReceive(BytesXMLMessage msg) {
if (msg instanceof TextMessage) {
System.out.println("Received: " + ((TextMessage) msg).getText());
}
latch.countDown();
}
@Override
public void onException(JCSMPException e) {
System.err.println("Consumer error: " + e.getMessage());
latch.countDown();
}
});
// Subscribe and start consuming
session.addSubscription(topic);
consumer.start();
// Set up producer
XMLMessageProducer producer = session.getMessageProducer(new JCSMPStreamingPublishCorrelatingEventHandler() {
@Override
public void responseReceivedEx(Object key) {
System.out.println("Message acknowledged");
}
@Override
public void handleErrorEx(Object key, JCSMPException cause, long timestamp) {
System.err.println("Producer error: " + cause.getMessage());
}
});
// Create and send message
TextMessage message = JCSMPFactory.onlyInstance().createMessage(TextMessage.class);
message.setText("Hello World");
message.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.send(message, topic);
// Wait for response
latch.await(10, TimeUnit.SECONDS);
// Cleanup
consumer.close();
session.closeSession();
}
}
}
```
--------------------------------
### Default Solace OAuth2 Token Provider Implementation
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This Java code snippet points to the `DefaultSolaceSessionOAuth2TokenProvider` class, which provides a sample implementation for the `SolaceSessionOAuth2TokenProvider` interface. It serves as a reference for creating custom token injection logic.
```java
// com.solacesystems.jcsmp.DefaultSolaceSessionOAuth2TokenProvider
```
--------------------------------
### Solace Java API Configuration Properties (Properties)
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
Defines the configuration properties for connecting to a Solace broker using the Java API within a Spring Boot application. These properties are typically placed in `application.properties`.
```properties
# application.properties - Solace Java API Configuration
# Required: Broker connection (format: [Protocol:]Host[:Port])
solace.java.host=tcp://localhost:55555
# Message VPN (default: "default")
solace.java.msgVpn=default
# Authentication
solace.java.clientUsername=default
solace.java.clientPassword=default
# Optional: Client identifier
solace.java.clientName=my-app-client
# Connection retry settings (defaults optimized for HA pairs)
solace.java.connectRetries=1
solace.java.reconnectRetries=-1
solace.java.connectRetriesPerHost=20
solace.java.reconnectRetryWaitInMillis=3000
# Additional API properties (from JCSMPProperties constants)
solace.java.apiProperties.reapply_subscriptions=false
solace.java.apiProperties.ssl_trust_store=/path/to/truststore
solace.java.apiProperties.client_channel_properties.keepAliveIntervalInMillis=3000
```
--------------------------------
### JNDI Lookup for JMS Objects in Java
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This Java code demonstrates how to configure and use Spring's JndiTemplate to perform JNDI lookups for JMS ConnectionFactory and destinations. It sets up JmsTemplate for producers and DefaultJmsListenerContainerFactory for consumers, utilizing JndiDestinationResolver for dynamic destination resolution.
```java
package jndidemo;
import jakarta.jms.ConnectionFactory;
import javax.naming.NamingException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.support.destination.JndiDestinationResolver;
import org.springframework.jndi.JndiObjectFactoryBean;
import org.springframework.jndi.JndiTemplate;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;
@SpringBootApplication
public class JndiApplication {
public static void main(String[] args) {
SpringApplication.run(JndiApplication.class, args);
}
@Service
static class MessageProducer implements CommandLineRunner {
@Autowired
private JmsTemplate producerJmsTemplate;
@Value("${solace.jms.demoProducerQueueJndiName}")
private String queueJndiName;
public void run(String... args) throws Exception {
String message = "Hello World via JNDI";
System.out.println("Sending: " + message);
producerJmsTemplate.convertAndSend(queueJndiName, message);
}
}
@EnableJms
@Configuration
static class JndiProducerConfig {
@Value("${solace.jms.demoConnectionFactoryJndiName}")
private String connectionFactoryJndiName;
@Autowired
private JndiTemplate jndiTemplate;
private ConnectionFactory lookupConnectionFactory() throws NamingException {
JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
factoryBean.setJndiTemplate(jndiTemplate);
factoryBean.setJndiName(connectionFactoryJndiName);
factoryBean.afterPropertiesSet();
return (ConnectionFactory) factoryBean.getObject();
}
@Bean
public JmsTemplate producerJmsTemplate() throws NamingException {
CachingConnectionFactory ccf = new CachingConnectionFactory(lookupConnectionFactory());
ccf.setSessionCacheSize(10);
JndiDestinationResolver resolver = new JndiDestinationResolver();
resolver.setCache(true);
resolver.setJndiTemplate(jndiTemplate);
JmsTemplate template = new JmsTemplate(ccf);
template.setDeliveryPersistent(true);
template.setDestinationResolver(resolver);
return template;
}
}
@EnableJms
@Configuration
static class JndiConsumerConfig {
@Value("${solace.jms.demoConnectionFactoryJndiName}")
private String connectionFactoryJndiName;
@Autowired
private JndiTemplate jndiTemplate;
@Bean
public DefaultJmsListenerContainerFactory cFactory() throws NamingException {
JndiObjectFactoryBean factoryBean = new JndiObjectFactoryBean();
factoryBean.setJndiTemplate(jndiTemplate);
factoryBean.setJndiName(connectionFactoryJndiName);
factoryBean.afterPropertiesSet();
JndiDestinationResolver resolver = new JndiDestinationResolver();
resolver.setCache(true);
resolver.setJndiTemplate(jndiTemplate);
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory((ConnectionFactory) factoryBean.getObject());
factory.setDestinationResolver(resolver);
factory.setConcurrency("3-10");
return factory;
}
}
static class MessageHandler {
@JmsListener(destination = "${solace.jms.demoConsumerQueueJndiName}", containerFactory = "cFactory")
public void processMessage(Message> msg) {
System.out.println("Received via JNDI: " + msg.getPayload());
}
}
}
```
--------------------------------
### Add Solace Spring Boot Dependencies (Maven)
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
Manages Solace Spring Boot dependency versions using the Bill of Materials (BOM) in a Maven project. Includes dependencies for the combined starter, Java API starter, or JMS API starter.
```xml
com.solace.spring.boot
solace-spring-boot-bom
2.5.0
pom
import
com.solace.spring.boot
solace-spring-boot-starter
com.solace.spring.boot
solace-java-spring-boot-starter
com.solace.spring.boot
solace-jms-spring-boot-starter
```
--------------------------------
### Solace Java API Configuration Properties (YAML)
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
Defines the configuration properties for connecting to a Solace broker using the Java API within a Spring Boot application. These properties are typically placed in `application.yml`.
```yaml
# application.yml - Solace Java API Configuration
solace:
java:
host: tcp://localhost:55555
msgVpn: default
clientUsername: default
clientPassword: default
connectRetries: 1
reconnectRetries: -1
connectRetriesPerHost: 20
reconnectRetryWaitInMillis: 3000
apiProperties:
reapply_subscriptions: false
ssl_trust_store: /path/to/truststore
```
--------------------------------
### Autowire JCSMPProperties in Spring Boot Application
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
Shows how to inject `JCSMPProperties` directly into your Spring Boot application using `@Autowired`. This allows for manual creation of a customized `SpringJCSMPFactory` if needed.
```java
/* The properties of a JCSMP connection */
@Autowired
private JCSMPProperties jcsmpProperties;
```
--------------------------------
### Configure Solace OAuth2 Authentication Properties
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This configuration block shows how to set up the necessary properties in `application.properties` for OAuth2 authentication with Solace. It includes client registration details, provider information, and Solace-specific connection settings for OAuth2.
```properties
spring.security.oauth2.client.registration.my-oauth2-client.provider=my-auth-server
spring.security.oauth2.client.registration.my-oauth2-client.client-id=replace-client-id-here
spring.security.oauth2.client.registration.my-oauth2-client.client-secret=replace-client-secret-here
spring.security.oauth2.client.registration.my-oauth2-client.authorization-grant-type=client_credentials ## only client_credentials grant type is supported
spring.security.oauth2.client.provider.my-auth-server.token-uri=replace-token-uri-here
solace.java.host=tcps://localhost:55443 ## OATUH2 authentication scheme requires a secure connection to the broker
solace.java.msgVpn=replace-msgVpn-here
solace.java.oauth2ClientRegistrationId=my-oauth2-client ## Refers to the Spring OAuth2 client registration-id defined above
solace.java.apiProperties.AUTHENTICATION_SCHEME=AUTHENTICATION_SCHEME_OAUTH2
```
--------------------------------
### Spring Boot OAuth2 and Solace Configuration
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This YAML configuration sets up Spring Security OAuth2 client and Solace connection properties. It defines the OAuth2 client registration, provider details including the token URI, and Solace broker connection parameters such as host, message VPN, retry settings, and the crucial OAuth2 client registration ID and authentication scheme.
```yaml
# application.yml - OAuth2 Configuration
spring:
security:
oauth2:
client:
registration:
my-oauth2-client:
provider: my-auth-server
client-id: your-client-id
client-secret: your-client-secret
authorization-grant-type: client_credentials
# scope: optional-scopes
provider:
my-auth-server:
token-uri: https://auth-server.example.com/oauth/token
solace:
java:
host: tcps://broker.example.com:55443 # Secure connection required
msgVpn: default
connectRetries: 3
reconnectRetries: 3
connectRetriesPerHost: 1
reconnectRetryWaitInMillis: 3000
oauth2ClientRegistrationId: my-oauth2-client # References registration above
apiProperties:
AUTHENTICATION_SCHEME: AUTHENTICATION_SCHEME_OAUTH2
# SSL_VALIDATE_CERTIFICATE: false # Only for development with self-signed certs
```
--------------------------------
### Add Solace JMS Spring Boot Starter Dependency (Maven)
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-jms-spring-boot-starter/README.md
Includes the Solace JMS Spring Boot starter in your project using Maven. This dependency enables auto-configuration of Solace JMS within your Spring Boot application.
```xml
com.solace.spring.boot
solace-jms-spring-boot-starter
5.2.0
```
--------------------------------
### Add Solace JMS Spring Boot Starter Dependency (Gradle)
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-jms-spring-boot-starter/README.md
Includes the Solace JMS Spring Boot starter in your project using Gradle. This dependency allows for auto-configuration of Solace JMS within your Spring Boot application.
```groovy
compile("com.solace.spring.boot:solace-jms-spring-boot-starter:5.2.0")
```
--------------------------------
### Configure Solace Java API Properties in application.properties
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This snippet shows how to configure direct Solace Java API properties within the application.properties file. These properties control connection details and retry mechanisms for the Solace Java API. Sensible defaults are provided, allowing developers to configure only essential properties like 'solace.java.host'.
```properties
solace.java.host
solace.java.msgVpn
solace.java.clientUsername
solace.java.clientPassword
solace.java.clientName
solace.java.connectRetries
solace.java.reconnectRetries
solace.java.connectRetriesPerHost
solace.java.reconnectRetryWaitInMillis
solace.java.oauth2ClientRegistrationId
```
--------------------------------
### Solace Java API with OAuth2 in Spring Boot
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This Java code demonstrates how to use the Solace Java API with OAuth2 authentication within a Spring Boot application. It configures a session using a pre-configured OAuth2 token provider, sets up a consumer and producer, and sends a message. Ensure your Spring JCSMPFactory is correctly configured for OAuth2.
```java
package demo;
import com.solacesystems.jcsmp.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@SpringBootApplication
@EnableWebSecurity
public class OAuth2Application {
public static void main(String[] args) {
SpringApplication.run(OAuth2Application.class, args);
}
@Component
static class OAuth2Runner implements CommandLineRunner {
@Autowired
private SpringJCSMPFactory solaceFactory;
public void run(String... args) throws Exception {
// Factory is pre-configured with OAuth2 token provider
final JCSMPSession session = solaceFactory.createSession();
final Topic topic = JCSMPFactory.onlyInstance().createTopic("tutorial/topic");
// Set up consumer
XMLMessageConsumer consumer = session.getMessageConsumer(new XMLMessageListener() {
@Override
public void onReceive(BytesXMLMessage msg) {
if (msg instanceof TextMessage) {
System.out.println("Received: " + ((TextMessage) msg).getText());
}
}
@Override
public void onException(JCSMPException e) {
System.err.println("Error: " + e.getMessage());
}
});
session.addSubscription(topic);
consumer.start();
// Send message
XMLMessageProducer producer = session.getMessageProducer(new JCSMPStreamingPublishCorrelatingEventHandler() {
@Override
public void responseReceivedEx(Object key) {}
@Override
public void handleErrorEx(Object key, JCSMPException cause, long timestamp) {
System.err.println("Send error: " + cause.getMessage());
}
});
TextMessage message = JCSMPFactory.onlyInstance().createMessage(TextMessage.class);
message.setText("Hello with OAuth2!");
message.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.send(message, topic);
Thread.sleep(5000);
consumer.close();
session.closeSession();
}
}
}
```
--------------------------------
### Autowire Solace JMS ConnectionFactory and JndiTemplate
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-jms-spring-boot-starter/README.md
Demonstrates how to autowire `ConnectionFactory` for direct JMS usage and `JndiTemplate` for JNDI lookup within a Spring application. These are essential for establishing connections to the Solace message routing service.
```java
@Autowired
private ConnectionFactory connectionFactory; // for JMS
```
```java
@Autowired
private JndiTemplate jndiTemplate; // for JNDI
```
--------------------------------
### Configure Additional Solace Java API Properties
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This snippet demonstrates how to configure additional Solace Java API properties that are not directly exposed in the application.properties. These properties are set using the 'solace.java.apiProperties.' prefix, allowing for fine-grained control over API behavior, such as subscription reapplication or SSL settings. Direct 'solace.java.' properties take precedence.
```properties
solace.java.apiProperties.reapply_subscriptions=false
solace.java.apiProperties.ssl_trust_store=/path/to/truststore
solace.java.apiProperties.client_channel_properties.keepAliveIntervalInMillis=3000
```
--------------------------------
### Autowire SpringJCSMPFactory in Spring Boot Application
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
Demonstrates how to automatically inject the `SpringJCSMPFactory` into your Spring Boot application using the `@Autowired` annotation. This factory can then be used to create Solace JCSMP sessions.
```java
@Autowired
private SpringJCSMPFactory solaceFactory;
// ... later in your code ...
final JCSMPSession session = solaceFactory.createSession();
```
--------------------------------
### Configure Solace JMS Properties
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-jms-spring-boot-starter/README.md
Shows how to configure Solace JMS connection properties using the `application.properties` file. These properties include host, message VPN, client username, and client password, allowing users to control the Solace JMS API settings.
```properties
solace.jms.host
solace.jms.msgVpn
solace.jms.clientUsername
solace.jms.clientPassword
```
--------------------------------
### Solace JMS Configuration Properties for Spring Boot
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
This section outlines the properties required in `application.properties` to configure the Solace JMS connection. It covers essential parameters like host, VPN, authentication credentials, and optional settings for direct transport and API properties.
```properties
# application.properties - Solace JMS Configuration
# Required: Broker connection
solace.jms.host=tcp://localhost:55555
# Message VPN
solace.jms.msgVpn=default
# Authentication
solace.jms.clientUsername=default
solace.jms.clientPassword=default
# Optional: Client name
solace.jms.clientName=my-jms-client
# Direct transport (higher performance, limited JMS features)
solace.jms.directTransport=false
# Additional JMS API properties (from SupportedProperty constants)
solace.jms.apiProperties.Solace_JMS_DynamicDurables=true
solace.jms.apiProperties.Solace_JMS_SSL_TrustStore=/path/to/truststore
# Application-specific queue name
solace.jms.demoQueueName=tutorial/queue
# Logging
logging.level.com.solacesystems=INFO
```
--------------------------------
### Custom Solace OAuth2 Token Provider Interface
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This Java code snippet references the `SolaceSessionOAuth2TokenProvider` interface, which is used for customizing the initial injection of OAuth2 tokens when using the Solace Java API. Developers can create their own implementations for specific token retrieval logic.
```java
// com.solacesystems.jcsmp.SolaceSessionOAuth2TokenProvider
```
--------------------------------
### Custom Solace OAuth2 Session Event Handler Interface
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-java-spring-boot-starter/README.md
This Java code snippet references the `SolaceOAuth2SessionEventHandler` interface, designed for customizing how OAuth2 tokens are refreshed when using the Solace Java API. Custom implementations can define specific token refresh strategies.
```java
// com.solacesystems.jcsmp.SolaceOAuth2SessionEventHandler
```
--------------------------------
### JNDI Configuration Properties for Solace JMS
Source: https://context7.com/solaceproducts/solace-spring-boot/llms.txt
These properties configure the connection to the Solace broker and specify the JNDI names for the ConnectionFactory and destinations. Ensure these JNDI names are provisioned on your Solace broker.
```properties
# application.properties - JNDI Configuration
solace.jms.host=tcp://localhost:55555
solace.jms.msgVpn=default
solace.jms.clientUsername=default
solace.jms.clientPassword=default
# JNDI names (must be provisioned on Solace broker)
solace.jms.demoConnectionFactoryJndiName=/jms/cf/default
solace.jms.demoProducerQueueJndiName=jndi/tutorial/queue
solace.jms.demoConsumerQueueJndiName=jndi/tutorial/queue
```
--------------------------------
### Configure Solace JMS API Properties in Spring Boot
Source: https://github.com/solaceproducts/solace-spring-boot/blob/master/solace-spring-boot-starters/solace-jms-spring-boot-starter/README.md
This snippet demonstrates how to set specific Solace JMS API properties using the `solace.jms.apiProperties` prefix in a Spring Boot application's configuration. This allows for fine-grained control over JMS client behavior beyond the standard properties. The format is `solace.jms.apiProperties.=`.
```properties
solace.jms.apiProperties.Solace_JMS_SSL_TrustStore=ABC
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.