Skip to content

Commit 5e2276d

Browse files
Code sample - 23c Quarkus Telegram Chatbot (#312)
* Code sample - 23c Quarkus Telegram Chatbot * additional adjustments * additional adjustments * remove target directory * fix indentation + close JDBC resources
1 parent 8307edb commit 5e2276d

File tree

14 files changed

+1106
-0
lines changed

14 files changed

+1106
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# telegram-bot-quarkus-23c
2+
[How to send notifications from a Quarkus app to a Telegram Chatbot using Java and the Oracle Database 23c Free](https://juarezjunior.medium.com/how-to-send-notifications-from-a-quarkus-app-to-a-telegram-chatbot-using-java-and-the-oracle-6fc6940ac8d5)

java/telegram-bot-quarkus/pom.xml

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0"?>
2+
<project
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<modelVersion>4.0.0</modelVersion>
7+
<groupId>com.oracle.dev.jdbc</groupId>
8+
<artifactId>telegram-bot-quarkus</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<properties>
11+
<compiler-plugin.version>3.11.0</compiler-plugin.version>
12+
<maven.compiler.release>21</maven.compiler.release>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
15+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
16+
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
17+
<quarkus.platform.version>3.0.3.Final</quarkus.platform.version>
18+
<skipITs>true</skipITs>
19+
<surefire-plugin.version>3.0.0</surefire-plugin.version>
20+
</properties>
21+
<dependencyManagement>
22+
<dependencies>
23+
<dependency>
24+
<groupId>${quarkus.platform.group-id}</groupId>
25+
<artifactId>${quarkus.platform.artifact-id}</artifactId>
26+
<version>${quarkus.platform.version}</version>
27+
<type>pom</type>
28+
<scope>import</scope>
29+
</dependency>
30+
</dependencies>
31+
</dependencyManagement>
32+
<dependencies>
33+
<dependency>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-resteasy-reactive-jsonb</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>io.quarkus</groupId>
39+
<artifactId>quarkus-rest-client-reactive-jsonb</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.quarkus</groupId>
43+
<artifactId>quarkus-scheduler</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.quarkus</groupId>
47+
<artifactId>quarkus-arc</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.quarkus</groupId>
51+
<artifactId>quarkus-resteasy-reactive</artifactId>
52+
</dependency>
53+
<dependency>
54+
<groupId>io.quarkus</groupId>
55+
<artifactId>quarkus-junit5</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>io.rest-assured</groupId>
60+
<artifactId>rest-assured</artifactId>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>com.oracle.database.jdbc</groupId>
65+
<artifactId>ojdbc11</artifactId>
66+
<version>23.4.0.24.05</version>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.slf4j</groupId>
70+
<artifactId>slf4j-api</artifactId>
71+
<version>2.0.7</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.slf4j</groupId>
75+
<artifactId>slf4j-simple</artifactId>
76+
<version>2.0.7</version>
77+
</dependency>
78+
</dependencies>
79+
<build>
80+
<plugins>
81+
<plugin>
82+
<groupId>${quarkus.platform.group-id}</groupId>
83+
<artifactId>quarkus-maven-plugin</artifactId>
84+
<version>${quarkus.platform.version}</version>
85+
<extensions>true</extensions>
86+
<executions>
87+
<execution>
88+
<goals>
89+
<goal>build</goal>
90+
<goal>generate-code</goal>
91+
<goal>generate-code-tests</goal>
92+
</goals>
93+
</execution>
94+
</executions>
95+
</plugin>
96+
<plugin>
97+
<artifactId>maven-compiler-plugin</artifactId>
98+
<version>${compiler-plugin.version}</version>
99+
</plugin>
100+
<plugin>
101+
<artifactId>maven-surefire-plugin</artifactId>
102+
<version>${surefire-plugin.version}</version>
103+
<configuration>
104+
<systemPropertyVariables>
105+
<java.util.logging.manager>
106+
org.jboss.logmanager.LogManager</java.util.logging.manager>
107+
<maven.home>${maven.home}</maven.home>
108+
</systemPropertyVariables>
109+
</configuration>
110+
</plugin>
111+
<plugin>
112+
<artifactId>maven-failsafe-plugin</artifactId>
113+
<version>${surefire-plugin.version}</version>
114+
<executions>
115+
<execution>
116+
<goals>
117+
<goal>integration-test</goal>
118+
<goal>verify</goal>
119+
</goals>
120+
<configuration>
121+
<systemPropertyVariables>
122+
<native.image.path>
123+
${project.build.directory}/${project.build.finalName}-runner</native.image.path>
124+
<java.util.logging.manager>
125+
org.jboss.logmanager.LogManager</java.util.logging.manager>
126+
<maven.home>${maven.home}</maven.home>
127+
</systemPropertyVariables>
128+
</configuration>
129+
</execution>
130+
</executions>
131+
</plugin>
132+
</plugins>
133+
</build>
134+
<profiles>
135+
<profile>
136+
<id>native</id>
137+
<activation>
138+
<property>
139+
<name>native</name>
140+
</property>
141+
</activation>
142+
<properties>
143+
<skipITs>false</skipITs>
144+
<quarkus.package.type>native</quarkus.package.type>
145+
</properties>
146+
</profile>
147+
</profiles>
148+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
CREATE USER BOT_USER IDENTIFIED BY <YOUR_PASSWORD> QUOTA UNLIMITED ON USERS;
2+
GRANT DB_DEVELOPER_ROLE TO BOT_USER;
3+
GRANT CREATE SESSION TO BOT_USER;
4+
GRANT SELECT ANY TABLE ON SCHEMA BOT_USER TO BOT_USER;
5+
GRANT INSERT ANY TABLE ON SCHEMA BOT_USER TO BOT_USER;
6+
GRANT UPDATE ANY TABLE ON SCHEMA BOT_USER TO BOT_USER;
7+
GRANT DELETE ANY TABLE ON SCHEMA BOT_USER TO BOT_USER;
8+
ALTER SESSION SET CURRENT_SCHEMA = BOT_USER;
9+
10+
CREATE TABLE Healthy
11+
(id NUMBER(10) CONSTRAINT pk_healthy PRIMARY KEY,
12+
tip VARCHAR2(70));
13+
14+
INSERT INTO Healthy VALUES(1,'Small changes can make a big difference. Start TODAY!');
15+
INSERT INTO Healthy VALUES(2,'Base your meals on higher fibre starchy carbohydrates');
16+
INSERT INTO Healthy VALUES(3,'Eat lots of fruit and vegetables');
17+
INSERT INTO Healthy VALUES(4,'Eat more fish, including a portion of oily fish');
18+
INSERT INTO Healthy VALUES(5,'Cut down on saturated fat and sugar');
19+
INSERT INTO Healthy VALUES(6,'Eat less salt: no more than 6g a day for adults');
20+
INSERT INTO Healthy VALUES(7,'Get active and be a healthy weight');
21+
INSERT INTO Healthy VALUES(8,'Do not get thirsty');
22+
INSERT INTO Healthy VALUES(9,'Do not skip breakfast');
23+
INSERT INTO Healthy VALUES(10,'Eat more vegetables, salad and fruit - Up to seven servings a day');
24+
INSERT INTO Healthy VALUES(11,'Limit intake of high fat, sugar, salt (HFSS) food and drinks ');
25+
INSERT INTO Healthy VALUES(12,'Size matters: Use the food pyramid as a guide for serving sizes');
26+
INSERT INTO Healthy VALUES(13,'Increase your physical activity levels');
27+
28+
COMMIT;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
3+
#
4+
# Before building the container image run:
5+
#
6+
# ./mvnw package
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/telegram-bot-quarkus-23c-jvm .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/telegram-bot-quarkus-23c-jvm
15+
#
16+
# If you want to include the debug port into your docker image
17+
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
18+
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
19+
# when running the container
20+
#
21+
# Then run the container using :
22+
#
23+
# docker run -i --rm -p 8080:8080 quarkus/telegram-bot-quarkus-23c-jvm
24+
#
25+
# This image uses the `run-java.sh` script to run the application.
26+
# This scripts computes the command line to execute your Java application, and
27+
# includes memory/GC tuning.
28+
# You can configure the behavior using the following environment properties:
29+
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class")
30+
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
31+
# in JAVA_OPTS (example: "-Dsome.property=foo")
32+
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
33+
# used to calculate a default maximal heap memory based on a containers restriction.
34+
# If used in a container without any memory constraints for the container then this
35+
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
36+
# of the container available memory as set here. The default is `50` which means 50%
37+
# of the available memory is used as an upper boundary. You can skip this mechanism by
38+
# setting this value to `0` in which case no `-Xmx` option is added.
39+
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
40+
# is used to calculate a default initial heap memory based on the maximum heap memory.
41+
# If used in a container without any memory constraints for the container then this
42+
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
43+
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
44+
# is used as the initial heap size. You can skip this mechanism by setting this value
45+
# to `0` in which case no `-Xms` option is added (example: "25")
46+
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
47+
# This is used to calculate the maximum value of the initial heap memory. If used in
48+
# a container without any memory constraints for the container then this option has
49+
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
50+
# here. The default is 4096MB which means the calculated value of `-Xms` never will
51+
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
52+
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
53+
# when things are happening. This option, if set to true, will set
54+
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
55+
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
56+
# true").
57+
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
58+
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
59+
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
60+
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
61+
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
62+
# (example: "20")
63+
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
64+
# (example: "40")
65+
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
66+
# (example: "4")
67+
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
68+
# previous GC times. (example: "90")
69+
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
70+
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
71+
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
72+
# contain the necessary JRE command-line options to specify the required GC, which
73+
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
74+
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
75+
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
76+
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
77+
# accessed directly. (example: "foo.example.com,bar.example.com")
78+
#
79+
###
80+
FROM registry.access.redhat.com/ubi8/openjdk-17:1.14
81+
82+
ENV LANGUAGE='en_US:en'
83+
84+
85+
# We make four distinct layers so if there are application changes the library layers can be re-used
86+
COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
87+
COPY --chown=185 target/quarkus-app/*.jar /deployments/
88+
COPY --chown=185 target/quarkus-app/app/ /deployments/app/
89+
COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
90+
91+
EXPOSE 8080
92+
USER 185
93+
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
94+
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
95+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode
3+
#
4+
# Before building the container image run:
5+
#
6+
# ./mvnw package -Dquarkus.package.type=legacy-jar
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/telegram-bot-quarkus-23c-legacy-jar .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/telegram-bot-quarkus-23c-legacy-jar
15+
#
16+
# If you want to include the debug port into your docker image
17+
# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005.
18+
# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005
19+
# when running the container
20+
#
21+
# Then run the container using :
22+
#
23+
# docker run -i --rm -p 8080:8080 quarkus/telegram-bot-quarkus-23c-legacy-jar
24+
#
25+
# This image uses the `run-java.sh` script to run the application.
26+
# This scripts computes the command line to execute your Java application, and
27+
# includes memory/GC tuning.
28+
# You can configure the behavior using the following environment properties:
29+
# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class")
30+
# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options
31+
# in JAVA_OPTS (example: "-Dsome.property=foo")
32+
# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is
33+
# used to calculate a default maximal heap memory based on a containers restriction.
34+
# If used in a container without any memory constraints for the container then this
35+
# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio
36+
# of the container available memory as set here. The default is `50` which means 50%
37+
# of the available memory is used as an upper boundary. You can skip this mechanism by
38+
# setting this value to `0` in which case no `-Xmx` option is added.
39+
# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This
40+
# is used to calculate a default initial heap memory based on the maximum heap memory.
41+
# If used in a container without any memory constraints for the container then this
42+
# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio
43+
# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx`
44+
# is used as the initial heap size. You can skip this mechanism by setting this value
45+
# to `0` in which case no `-Xms` option is added (example: "25")
46+
# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
47+
# This is used to calculate the maximum value of the initial heap memory. If used in
48+
# a container without any memory constraints for the container then this option has
49+
# no effect. If there is a memory constraint then `-Xms` is limited to the value set
50+
# here. The default is 4096MB which means the calculated value of `-Xms` never will
51+
# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096")
52+
# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output
53+
# when things are happening. This option, if set to true, will set
54+
# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
55+
# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example:
56+
# true").
57+
# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787").
58+
# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
59+
# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2")
60+
# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024").
61+
# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion.
62+
# (example: "20")
63+
# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking.
64+
# (example: "40")
65+
# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection.
66+
# (example: "4")
67+
# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus
68+
# previous GC times. (example: "90")
69+
# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
70+
# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
71+
# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should
72+
# contain the necessary JRE command-line options to specify the required GC, which
73+
# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
74+
# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080")
75+
# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080")
76+
# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be
77+
# accessed directly. (example: "foo.example.com,bar.example.com")
78+
#
79+
###
80+
FROM registry.access.redhat.com/ubi8/openjdk-17:1.14
81+
82+
ENV LANGUAGE='en_US:en'
83+
84+
85+
COPY target/lib/* /deployments/lib/
86+
COPY target/*-runner.jar /deployments/quarkus-run.jar
87+
88+
EXPOSE 8080
89+
USER 185
90+
ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager"
91+
ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
####
2+
# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode.
3+
#
4+
# Before building the container image run:
5+
#
6+
# ./mvnw package -Pnative
7+
#
8+
# Then, build the image with:
9+
#
10+
# docker build -f src/main/docker/Dockerfile.native -t quarkus/telegram-bot-quarkus-23c .
11+
#
12+
# Then run the container using:
13+
#
14+
# docker run -i --rm -p 8080:8080 quarkus/telegram-bot-quarkus-23c
15+
#
16+
###
17+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6
18+
WORKDIR /work/
19+
RUN chown 1001 /work \
20+
&& chmod "g+rwX" /work \
21+
&& chown 1001:root /work
22+
COPY --chown=1001:root target/*-runner /work/application
23+
24+
EXPOSE 8080
25+
USER 1001
26+
27+
CMD ["./application", "-Dquarkus.http.host=0.0.0.0"]

0 commit comments

Comments
 (0)