### Publisher Confirmations Example Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example demonstrating how to use CorrelationData to wait for publish confirmations from the broker. ```java @Autowired private StreamBridge streamBridge; public void send(String payload, long timeout, TimeUnit unit) { CorrelationData correlationData = new CorrelationData(); Message message = MessageBuilder.withPayload(payload) .setHeader(SolaceBinderHeaders.CONFIRM_CORRELATION, correlationData) .build(); streamBridge.send("output-destination", message); try { correlationData.getFuture().get(timeout, unit); // Do success logic } catch (InterruptedException | ExecutionException | TimeoutException e) { // Do failure logic } } ``` -------------------------------- ### Batch Consumer Example Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of how to consume batched messages in Spring Cloud Stream. It demonstrates accessing the list of payloads and their corresponding headers. ```java @Bean Consumer>> input() { return batchMsg -> { // <1> List batchedPayloads = batchMsg.getPayload(); List> batchedHeaders = (List>) batchMsg.getHeaders().get(BinderHeaders.BATCH_HEADERS); // <2> for (int i = 0; i < batchedPayloads.size(); i++) { Payload payload = batchedPayloads.get(i); Map headers = batchedHeaders.get(i); // Process inidividual message payload and its headers } }; } ``` -------------------------------- ### Batch Producer Example Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of how to publish batched messages using Spring Cloud Stream. It shows constructing a message with a list of payloads and custom headers. ```java @Bean Supplier>> output() { return () -> { List batchedPayloads = new ArrayList<>(); List> batchedHeaders = new ArrayList<>(); for (int i = 0; i < 100; i++) { // Create batched message contents batchedPayloads.add(new Payload(i)); batchedHeaders.add(Map.of("my-header", "my-header-value")); } // construct batched message return MessageBuilder.withPayload(batchedPayloads) .setHeader(BinderHeaders.BATCH_HEADERS, batchedHeaders) .build(); }; } ``` -------------------------------- ### Publishing Partitioned Messages Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of how to build a message with a partition key header for partitioned queues. ```java public class MyMessageBuilder { public Message buildMeAMessage() { return MessageBuilder.withPayload("payload") .setHeader(SolaceBinderHeaders.PARTITION_KEY, "partition-key") .build(); } } ``` -------------------------------- ### Example Configuration Parameters Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder-opentelemetry/README.adoc A basic set of JVM arguments for configuring the OpenTelemetry agent, Solace JCSMP integration, and Spring Cloud Stream Solace Binder instrumentation. ```bash -javaagent:/path/to/opentelemetry-javaagent.jar -Dotel.javaagent.extensions=/path/to/solace-opentelemetry-jcsmp-integration.jar,/path/to/spring-cloud-stream-binder-solace-instrumentation.jar -Dotel.instrumentation.common.default-enabled=false -Dotel.javaagent.debug=true -Dotel.traces.exporter=otlp -Dotel.metrics.exporter=none -Dotel.logs.exporter=none -Dotel.exporter.otlp.protocol=grpc -Dotel.exporter.otlp.endpoint=http://localhost:4317 -Dotel.resource.attributes=service.name=my-solace-application -Dotel.service.name=my-solace-application -Dotel.propagators=solace_jcsmp_tracecontext -Dotel.java.disabled.resource.providers=io.opentelemetry.instrumentation.resources.ProcessResourceProvider -Dotel.instrumentation.solace-opentelemetry-jcsmp-integration.enabled=true -Dotel.instrumentation.spring-cloud-stream-binder-solace-instrumentation.enabled=true ``` -------------------------------- ### Using a pre-existing queue by its exact name Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of configuring queueNameExpression to use a specific queue name. ```yaml spring.cloud.stream.solace.bindings..consumer.queueNameExpression: "'my/existing/queue/name'" ``` -------------------------------- ### Sample Application with Solace Binding Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc An example Spring Boot application demonstrating the functional approach to defining Solace bindings using Spring Cloud Function. ```java @SpringBootApplication public class SampleAppApplication { public static void main(String[] args) { SpringApplication.run(SampleAppApp.class, args); } @Bean public Function uppercase() { return value -> value.toUpperCase(); } } ``` -------------------------------- ### SSL Trust Store Configuration Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of how to configure SSL trust store properties for the Solace Spring Cloud Stream Starter. ```properties # apiProperties: # ssl_trust_store: # ssl_trust_store_password: ``` -------------------------------- ### Dynamic Producer Destinations with StreamBridge Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example showing how to use `StreamBridge` with the `scst_targetDestination` header to send messages to a dynamically specified destination, by sending to a pre-defined output binding. ```java public void sendMessage(StreamBridge streamBridge, String myDynamicDestination, Message message) { Message messageWithDestination = MessageBuilder.fromMessage(message) .setHeader(BinderHeaders.TARGET_DESTINATION, myDynamicDestination) .build(); streamBridge.send("some-pre-defined-output-binding", messageWithDestination); } ``` -------------------------------- ### Solace Configuration for Spring Cloud Stream Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc An example Solace configuration file for Spring Cloud Stream, defining bindings and binder properties for a Solace broker. ```yaml spring: cloud: function: definition: uppercase stream: bindings: uppercase-in-0: destination: queuename group: myconsumergroup binder: solace-broker uppercase-out-0: destination: uppercase/topic binder: solace-broker binders: solace-broker: type: solace environment: solace: # <1> java: host: tcp://localhost:55555 msgVpn: default clientUsername: default clientPassword: default connectRetries: -1 reconnectRetries: -1 ``` -------------------------------- ### Applying queueNameExpression across all consumer bindings Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of setting the default queueNameExpression for all consumer bindings. ```yaml spring.cloud.stream.bindings..destination: "queue1" spring.cloud.stream.bindings..destination: "queue2" spring.cloud.stream.solace.default.consumer.queueNameExpression: "destination" ``` -------------------------------- ### Dynamic Producer Destinations with Message Headers Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example demonstrating how to use `scst_targetDestination` and `solace_scst_targetDestinationType` headers to dynamically route messages to specific Solace topics or queues, overriding the configured producer destination. ```java public class MyMessageBuilder { public Message buildMeAMessage() { return MessageBuilder.withPayload("payload") .setHeader(BinderHeaders.TARGET_DESTINATION, "some-dynamic-destination") // <1> .setHeader(SolaceBinderHeaders.TARGET_DESTINATION_TYPE, "topic") // <2> .build(); } } ``` -------------------------------- ### Manual Message Acknowledgment Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of how to disable auto-acknowledgement and manually acknowledge a message in a consumer. ```java public void consume(Message message) { AcknowledgmentCallback acknowledgmentCallback = StaticMessageHeaderAccessor.getAcknowledgmentCallback(message); // <1> acknowledgmentCallback.noAutoAck(); // <2> try { AckUtils.accept(acknowledgmentCallback); // <3> } catch (SolaceAcknowledgmentException e) {} // <4> } ``` -------------------------------- ### Using a pre-existing error queue by its exact name Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of configuring errorQueueNameExpression to use a specific error queue name. ```yaml spring.cloud.stream.solace.bindings..consumer.errorQueueNameExpression: "'my/existing/errorQueue/name'" ``` -------------------------------- ### Enabling the OpenTelemetry Agent Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder-opentelemetry/README.adoc JVM arguments required to enable the OpenTelemetry agent when starting your application. ```bash -javaagent:/path/to/opentelemetry-javaagent.jar ``` -------------------------------- ### Using the binding's destination value directly as the queue name Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Example of setting queueNameExpression to use the binding's destination. ```yaml spring.cloud.stream.bindings..destination: "my/existing/queue/name" sspring.cloud.stream.solace.bindings..consumer.queueNameExpression: "destination" ``` -------------------------------- ### Consumer and producer header name mapping Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc This YAML configuration example illustrates how to set up custom mappings between Spring Message header names and JCSMP User Property keys for both consumer and producer bindings. It shows specific mappings for headers like 'timestamp', 'id', 'contentType', and 'priority' for a binding named 'uppercase-in-0' (consumer) and 'uppercase-out-0' (producer). ```yaml spring: cloud: stream: solace: bindings: uppercase-in-0: consumer: header-name-mapping: timestamp: original-timestamp id: original-message-id contentType: original-content-type priority: original-priority uppercase-out-0: producer: header-name-mapping: original-timestamp: timestamp original-message-id: id original-content-type: contentType original-priority: priority ``` -------------------------------- ### Mutating SDTMap payload and failing the message Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc This example demonstrates how mutations to nested objects within a Spring Message payload can persist between retries when using Spring's Retry Template. It shows a function that adds a new key-value pair to an SDTMap payload and then throws a RuntimeException to trigger the retry mechanism. The comment highlights that the added key will persist in subsequent retry attempts if `maxAttempts` is greater than 1. ```java public Function, Message> transform() { return message -> { if (!message.getPayload().containsKey("new-key")) { // <1> message.getPayload().putString("new-key", "value"); } // failing message processing to trigger retry template throw new RuntimeException("Failed processing"); }; } ``` -------------------------------- ### Build Locally Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/README.md Clone the repository and run 'mvn package' at the root of the project to build the artifacts locally. ```shell git clone https://github.com/SolaceProducts/solace-spring-cloud.git cd solace-spring-cloud mvn package # or mvn install to install them locally ``` -------------------------------- ### Run All Tests Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/README.md Run the following command to execute all unit and integration tests. ```shell mvn clean verify ``` -------------------------------- ### Cloning Jaeger IDL and generating proto files Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder-opentelemetry/solace-spring-cloud-stream-binder-instrumentation-tests/src/test/java/io/jaegertracing/api_v3/README.MD This snippet shows how to clone the Jaeger IDL repository and generate the proto files. ```bash git clone https://github.com/jaegertracing/jaeger-idl.git cd jaeger-idl make proto-all ``` -------------------------------- ### Generate Root CA Key and Certificate Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder/src/test/resources/oauth2/certs/README.txt Commands to generate a private key and a self-signed certificate for the Root CA, and combine them into a PEM file. ```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 Keycloak Server Key and Certificate Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder/src/test/resources/oauth2/certs/README.txt Commands to generate a private key, a CSR, and sign it with the Root CA to create a certificate for the Keycloak server. ```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 ``` -------------------------------- ### Run Tests With An External Broker Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/README.md Environment variables can be set to direct the tests to use an external broker if Docker is not available. ```shell SOLACE_JAVA_HOST=tcp://localhost:55555 SOLACE_JAVA_CLIENT_USERNAME=default SOLACE_JAVA_CLIENT_PASSWORD=default SOLACE_JAVA_MSG_VPN=default TEST_SOLACE_MGMT_HOST=http://localhost:8080 TEST_SOLACE_MGMT_USERNAME=admin TEST_SOLACE_MGMT_PASSWORD=admin ``` -------------------------------- ### Gradle Dependency Management Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-bom/README.md Shows how to include the Solace Spring Cloud BOM in a Gradle project and how to use version-less Solace dependencies. ```groovy dependencies { implementation(platform("com.solace.spring.cloud:solace-spring-cloud-bom:6.0.0")) implementation("com.solace.spring.cloud:spring-cloud-starter-stream-solace") } ``` -------------------------------- ### Generate Solace Broker Key and Certificate Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder/src/test/resources/oauth2/certs/README.txt Commands to generate a private key, a CSR, and sign it with the Root CA to create a certificate for the Solace PubSub+ broker. ```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 ``` -------------------------------- ### Generate Solace Client Key and Certificate Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder/solace-spring-cloud-stream-binder/src/test/resources/oauth2/certs/README.txt Commands to generate a private key, a CSR, and sign it with the Root CA to create a certificate for the Solace PubSub+ client, including truststore and keystore creation. ```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 changeMe123 openssl 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 ``` -------------------------------- ### Release Process Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/README.md Commands for the release process. ```shell mvn -B release:prepare ``` -------------------------------- ### Maven dependency for Solace Spring Cloud Stream Binder Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Include the spring-cloud-starter-stream-solace in your project using Maven. ```xml com.solace.spring.cloud spring-cloud-starter-stream-solace {revnumber} ``` -------------------------------- ### Gradle dependency for Solace Spring Cloud Stream Binder Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter/README.adoc Include the spring-cloud-starter-stream-solace in your project using Gradle. ```groovy // Solace Spring Cloud Stream Binder compile("com.solace.spring.cloud:spring-cloud-starter-stream-solace:{revnumber}") ``` -------------------------------- ### Maven Dependency Management Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-bom/README.md Shows how to include the Solace Spring Cloud BOM in a Maven project's dependency management section and how to use version-less Solace dependencies. ```xml com.solace.spring.cloud solace-spring-cloud-bom 6.0.0 pom import com.solace.spring.cloud spring-cloud-starter-stream-solace ``` -------------------------------- ### Enable Solace Propagator Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder-opentelemetry/README.adoc Ensure the Solace propagator is enabled to correctly propagate trace context. ```shell -Dotel.propagators=solace_jcsmp_tracecontext ``` -------------------------------- ### Enable Debug Mode Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/solace-spring-cloud-stream-binder-opentelemetry/README.adoc Enable debug mode for the OpenTelemetry Java Agent to troubleshoot trace data issues. ```shell -Dotel.javaagent.debug=true ``` -------------------------------- ### Parallel Test Execution Source: https://github.com/solaceproducts/solace-spring-cloud/blob/master/README.md Parallel test execution is disabled by default. Add the '-Djunit.jupiter.execution.parallel.enabled=true' option to enable it. ```shell -Djunit.jupiter.execution.parallel.enabled=true ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.