You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add code in complete required for Docker Compose
This commit adds dependencies and a Docker Compose file
that is required to change the guide to use Docker compose
support. In this commit, only the complete folder is considered.
* Update README instructions for Docker Compose
Documented instructions for using Spring Boot Docker
Compose support to run the guide. This is the preferred
option for runnign the guide. Additional instructions for homebrew
installation were removed.
A section was added about running the application as a jar
and as a container. Native compilation was excluded as it would
require a custom hint because of how the guide is written.
Native was excluded as it was not simple to implement and custom
hints are beyond the scope of this guide.
* Update Initial folder to represent empty project
The initial folder is modified so that it is a true
representation of what will be downloaded from Spring
Initializr. This includes adding the new Docker Compose
dependency as well as a compose.yaml file.
* Remove reference to a web application
* Update typo in README
* Fix grammatical errors in README
Redis is an open source, BSD-licensed, key-value data store that also comes with a
34
-
messaging system. The server is freely available at https://redis.io/download. You can
35
-
download it manually, or, if you use a Mac, with Homebrew, by running the following
36
-
command in a terminal window:
37
-
38
-
====
39
-
[source,bash]
40
-
----
41
-
brew install redis
42
-
----
43
-
====
32
+
If you choose to run the Redis server yourself instead of using Spring Boot Docker Compose support, you have a few options:
33
+
- https://redis.io/download[Download the server] and manually run it
34
+
- Install with Homebrew, if you use a Mac
35
+
- Manually run the `compose.yaml` file with `docker compose up`
44
36
45
-
Once you unpack Redis, you can launch it with its default settings by running the following command:
46
-
47
-
====
48
-
[source,bash]
49
-
----
50
-
redis-server
51
-
----
52
-
====
53
-
54
-
You should see a message similar to the following:
55
-
56
-
====
57
-
[source,text]
58
-
----
59
-
[35142] 01 May 14:36:28.939 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
60
-
[35142] 01 May 14:36:28.940 * Max number of open files set to 10032
61
-
_._
62
-
_.-``__ ''-._
63
-
_.-`` `. `_. ''-._ Redis 2.6.12 (00000000/0) 64 bit
64
-
.-`` .-```. ```\/ _.,_ ''-._
65
-
( ' , .-` | `, ) Running in stand alone mode
66
-
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
67
-
| `-._ `._ / _.-' | PID: 35142
68
-
`-._ `-._ `-./ _.-' _.-'
69
-
|`-._`-._ `-.__.-' _.-'_.-'|
70
-
| `-._`-._ _.-'_.-' | https://redis.io
71
-
`-._ `-._`-.__.-'_.-' _.-'
72
-
|`-._`-._ `-.__.-' _.-'_.-'|
73
-
| `-._`-._ _.-'_.-' |
74
-
`-._ `-._`-.__.-'_.-' _.-'
75
-
`-._ `-.__.-' _.-'
76
-
`-._ _.-'
77
-
`-.__.-'
78
-
79
-
[35142] 01 May 14:36:28.941 # Server started, Redis version 2.6.12
80
-
[35142] 01 May 14:36:28.941 * The server is now ready to accept connections on port 6379
81
-
----
82
-
====
37
+
If you go with any of these alternate approaches, you should remove the `spring-boot-docker-compose` dependency from the Maven or Gradle build file.
38
+
You also need to add configuration to an `application.properties` file, as described in greater detail in the <<_preparing_to_build_the_application>> section.
39
+
As mentioned earlier, this guide assumes that you use Docker Compose support in Spring Boot, so additional changes to `application.properties` are not required at this point.
83
40
84
41
[[initial]]
85
42
== Starting with Spring Initializr
86
43
87
-
You can use this https://start.spring.io/#!type=maven-project&groupId=com.example&artifactId=messaging-redis&name=messaging-redis&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.messaging-redis&dependencies=data-redis[pre-initialized project] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
44
+
You can use this https://start.spring.io/#!type=maven-project&groupId=com.example&artifactId=messaging-redis&name=messaging-redis&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.messaging-redis&dependencies=data-redis,docker-compose[pre-initialized project^] and click Generate to download a ZIP file. This project is configured to fit the examples in this tutorial.
88
45
89
46
To manually initialize the project:
90
47
91
48
. Navigate to https://start.spring.io.
92
49
This service pulls in all the dependencies you need for an application and does most of the setup for you.
93
50
. Choose either Gradle or Maven and the language you want to use. This guide assumes that you chose Java.
94
-
. Click *Dependencies* and select *Spring Data Redis*.
51
+
. Click *Dependencies* and select *Spring Data Redis* and *Docker Compose Support*.
95
52
. Click *Generate*.
96
-
. Download the resulting ZIP file, which is an archive of a web application that is configured with your choices.
53
+
. Download the resulting ZIP file, which is an archive of an application that is configured with your choices.
97
54
98
55
NOTE: If your IDE has the Spring Initializr integration, you can complete this process from your IDE.
99
56
100
-
NOTE: You can also fork the project from Github and open it in your IDE or other editor.
101
-
102
57
== Create a Redis Message Receiver
103
58
104
59
In any messaging-based application, there are message publishers and messaging receivers.
@@ -166,44 +121,53 @@ container bean starts listening for messages. The `main()` method then retrieves
166
121
`Hello from Redis!` message on the `chat` topic. Finally, it closes the Spring application
Note that, if you have cloned the project from the solution repository, your IDE may look in the wrong place for the `compose.yaml` file.
128
+
You can configure your IDE to look in the correct place or you could use the command line to run the application.
129
+
The `./gradlew bootRun` and `./mvnw spring-boot:run` commands launch the application and automatically find the compose.yaml file.
172
130
173
-
You should see output similar to the following:
131
+
You should see the output:
174
132
175
133
====
176
-
[source,text]
134
+
[source,bash]
177
135
----
178
-
179
-
. ____ _ __ _ _
180
-
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
181
-
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
182
-
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
183
-
' |____| .__|_| |_|_| |_\__, | / / / /
184
-
=========|_|==============|___/=/_/_/_/
185
-
:: Spring Boot :: (v2.1.8.RELEASE)
186
-
187
-
2019-09-23 12:57:11.578 INFO 35396 --- [ main] c.e.m.MessagingRedisApplication : Starting MessagingRedisApplication on Jays-MBP with PID 35396 (/Users/j/projects/guides/gs-messaging-redis/complete/target/classes started by j in /Users/j/projects/guides/gs-messaging-redis/complete)
188
-
2019-09-23 12:57:11.581 INFO 35396 --- [ main] c.e.m.MessagingRedisApplication : No active profile set, falling back to default profiles: default
189
-
2019-09-23 12:57:11.885 INFO 35396 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
190
-
2019-09-23 12:57:11.887 INFO 35396 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
191
-
2019-09-23 12:57:11.914 INFO 35396 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 13ms. Found 0 repository interfaces.
192
-
2019-09-23 12:57:12.685 INFO 35396 --- [ container-1] io.lettuce.core.EpollProvider : Starting without optional epoll library
193
-
2019-09-23 12:57:12.685 INFO 35396 --- [ container-1] io.lettuce.core.KqueueProvider : Starting without optional kqueue library
194
-
2019-09-23 12:57:12.848 INFO 35396 --- [ main] c.e.m.MessagingRedisApplication : Started MessagingRedisApplication in 1.511 seconds (JVM running for 3.685)
2019-09-23 12:57:12.861 INFO 35396 --- [ container-2] com.example.messagingredis.Receiver : Received <Hello from Redis!>
136
+
yyyy-mm-ddT07:08:48.646-04:00 INFO 18338 --- [main] c.e.m.MessagingRedisApplication: Sending message...
137
+
yyyy-mm-ddT07:08:48.663-04:00 INFO 18338 --- [container-1] com.example.messagingredis.Receiver : Received <Hello from Redis!>
197
138
----
198
139
====
199
140
141
+
== Preparing to Build the Application
142
+
143
+
To run the code without Spring Boot Docker Compose support, you need a version of Redis running locally.
144
+
To do this, you can use Docker Compose, but you must first make two changes to the `compose.yaml` file.
145
+
First, modify the `ports` entry in `compose.yaml` to be `'6379:6379'`.
146
+
Second, add a `container_name`.
147
+
148
+
The `compose.yaml` should now be:
149
+
----
150
+
services:
151
+
redis:
152
+
container_name: 'guide-redis'
153
+
image: 'redis:latest'
154
+
ports:
155
+
- '6379:6379'
156
+
----
157
+
158
+
You can now run `docker compose up` to start the Redis server.
159
+
Now you should have an external Redis server that is ready to accept requests.
160
+
You can rerun the application and see the same output using your external Redis server.
161
+
162
+
NOTE: No configuration is required in the `application.properties` file because the default values match the Redis server configuration in `compose.yaml`. Specifically, the properties `spring.data.redis.host` and `spring.data.redis.port` default to `localhost` and `6379` respectively.
0 commit comments