Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
= Spring Boot Application for Hazelcast Viridian
= Spring Boot Application for Hazelcast Cloud
:experimental: true

This is an example of how to use Spring Boot with Hazelcast Viridian.
This is an example of how to use Spring Boot with Hazelcast {hazelcast-cloud}.

TIP: For step-by-step instructions of how to run this app, see the link:https://docs.hazelcast.com/tutorials/spring-boot-client[tutorial].

== Quickstart

. Add the required properties to `spring-sample/src/main/resources/application.properties`:

- `clusterName`
- `clusterId`
- `discoveryToken`
- `keyStorePassword`
- `trustStorePassword` (same as `keyStorePassword`)
Expand All @@ -24,7 +24,7 @@ TIP: For step-by-step instructions of how to run this app, see the link:https://

== Internal Hazelcast Developers

If you want to try this application in the UAT or DEV environment, edit the `src/main/java/sample/com/hazelcast/demo/viridian/HzViridianDemoApplication.java` file to include the environment URL:
If you want to try this application in the UAT or DEV environment, edit the `src/main/java/sample/com/hazelcast/demo/cloud/HzCloudDemoApplication.java` file to include the environment URL:

```java
// For DEV, use https://test.dev.hazelcast.cloud
Expand Down
20 changes: 11 additions & 9 deletions docs/modules/ROOT/pages/spring-boot-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You need the following:
- A xref:cloud:ROOT:create-serverless-cluster.adoc[{hazelcast-cloud} Standard cluster].
- link:https://git-scm.com/book/en/v2/Getting-Started-Installing-Git[Git]
- link:https://maven.apache.org/install.html[Maven]
- JDK 8
- JDK 17 or later
- `JAVA_HOME` environment variable set to the path of the JDK


Expand Down Expand Up @@ -61,9 +61,11 @@ cd spring-boot-sample

. Open the `src/main/resources/application.properties` file.

. Add connection credentials for your cluster to the `application.properties` file. You can find these credentials in the {hazelcast-cloud} dashboard for your cluster under *Connect Client* > *Advanced Setup*.
. Add connection credentials for your cluster to the `application.properties` file.
+
- `clusterName`
NOTE: You can find these credentials in the {hazelcast-cloud} dashboard for your cluster; clusterID is provided in the *Cluster details*, and the other credentials in the *Advanced* option under *Connect Client*.
+
- `clusterID`
- `discoveryToken`
- `keyStorePassword`
- `trustStorePassword` (same as `keyStorePassword`)
Expand All @@ -83,17 +85,17 @@ include::spring-boot-sample:example$pom.xml[tag=client]
link:{github-directory}/pom.xml[View source]
====

.`HzViridianDemoApplication.java`
.`HzCloudDemoApplication.java`
[%collapsible]
====
Spring Boot first attempts to create a Hazelcast client by checking the presence of a `com.hazelcast.client.config.ClientConfig` bean. This bean is configured using the information in the `application.properties` file.

[source,java]
----
include::spring-boot-sample:example$src/main/java/sample/com/hazelcast/demo/viridian/HzViridianDemoApplication.java[tag=class]
include::spring-boot-sample:example$src/main/java/sample/com/hazelcast/demo/cloud/HzCloudDemoApplication.java[tag=class]
----

link:{github-directory}/src/main/java/sample/com/hazelcast/demo/viridian/HzViridianDemoApplication.java[View source]
link:{github-directory}/src/main/java/sample/com/hazelcast/demo/cloud/HzCloudDemoApplication.java[View source]
====

.`MapService.java`
Expand All @@ -103,10 +105,10 @@ When the `com.hazelcast.client.config.ClientConfig` bean is present, a `Hazelcas

[source,java]
----
include::spring-boot-sample:example$src/main/java/sample/com/hazelcast/demo/viridian/MapService.java[tag=class]
include::spring-boot-sample:example$src/main/java/sample/com/hazelcast/demo/cloud/MapService.java[tag=class]
----

link:{github-directory}/src/main/java/sample/com/hazelcast/demo/viridian/MapService.java[View source]
link:{github-directory}/src/main/java/sample/com/hazelcast/demo/cloud/MapService.java[View source]
====

== Step 2. Connect the Client
Expand All @@ -131,7 +133,7 @@ mvnw.cmd spring-boot:run
--
====

The client connects to the cluster and adds 10 random entries to a map called `MyMap`.
The client connects to the cluster and adds ten random entries to a map called `MyMap`.

```
...
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.hz.demos</groupId>
<artifactId>hz-viridian-demo</artifactId>
<artifactId>hz-cloud-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>hz-viridian-demo</name>
<description>hz-viridian-demo</description>
<name>hz-cloud-demo</name>
<description>hz-cloud-demo</description>
<properties>
<java.version>11</java.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sample.com.hazelcast.demo.viridian;
package sample.com.hazelcast.demo.cloud;

import java.io.IOException;
import java.util.Properties;
Expand All @@ -15,24 +15,24 @@

// tag::class[]
@SpringBootApplication
public class HzViridianDemoApplication {
public class HzCloudDemoApplication {

public static void main(String[] args) {
SpringApplication.run(HzViridianDemoApplication.class, args);
SpringApplication.run(HzCloudDemoApplication.class, args);
}

@ConditionalOnProperty(
name = "hazelcast.viridian.tlsEnabled",
name = "hazelcast.cloud.tlsEnabled",
havingValue = "true"
)
@Bean
ClientConfig hazelcastClientConfig(
@Value("${hazelcast.viridian.discoveryToken}") String discoveryToken,
@Value("${hazelcast.viridian.clusterName}") String clusterName,
@Value("${hazelcast.viridian.keyStore}") Resource keyStore,
@Value("${hazelcast.viridian.keyStorePassword}") String keyStorePassword,
@Value("${hazelcast.viridian.trustStore}") Resource trustStore,
@Value("${hazelcast.viridian.trustStorePassword}") String trustStorePassword
@Value("${hazelcast.cloud.discoveryToken}") String discoveryToken,
@Value("${hazelcast.cloud.clusterId}") String clusterId,
@Value("${hazelcast.cloud.keyStore}") Resource keyStore,
@Value("${hazelcast.cloud.keyStorePassword}") String keyStorePassword,
@Value("${hazelcast.cloud.trustStore}") Resource trustStore,
@Value("${hazelcast.cloud.trustStorePassword}") String trustStorePassword
) throws IOException {
Properties props = new Properties();
props.setProperty("javax.net.ssl.keyStore", keyStore.getURI().getPath());
Expand All @@ -46,8 +46,8 @@ ClientConfig hazelcastClientConfig(
.getCloudConfig()
.setDiscoveryToken(discoveryToken)
.setEnabled(true);
config.setClusterName(clusterName);
config.setProperty("hazelcast.client.cloud.url", "https://api.viridian.hazelcast.com");
config.setClusterId(clusterId);
config.setProperty("hazelcast.client.cloud.url", "https://api.cloud.hazelcast.com");

return config;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sample.com.hazelcast.demo.viridian;
package sample.com.hazelcast.demo.cloud;

import java.util.Map;
import java.util.UUID;
Expand Down
14 changes: 7 additions & 7 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
hazelcast.viridian.clusterName=
hazelcast.viridian.discoveryToken=
hazelcast.viridian.tlsEnabled=true
hazelcast.viridian.keyStore=classpath:/client.keystore
hazelcast.viridian.keyStorePassword=
hazelcast.viridian.trustStore=classpath:/client.truststore
hazelcast.viridian.trustStorePassword=
hazelcast.cloud.clusterId=
hazelcast.cloud.discoveryToken=
hazelcast.cloud.tlsEnabled=true
hazelcast.cloud.keyStore=classpath:/client.keystore
hazelcast.cloud.keyStorePassword=
hazelcast.cloud.trustStore=classpath:/client.truststore
hazelcast.cloud.trustStorePassword=