From 579029d489c5622c295fa2536e1ff384a74aa32a Mon Sep 17 00:00:00 2001 From: Tiago Bueno <49003339+tlbueno@users.noreply.github.com> Date: Tue, 12 Nov 2024 11:17:14 -0300 Subject: [PATCH] Initial version Signed-off-by: Tiago Bueno <49003339+tlbueno@users.noreply.github.com> Co-authored: Clebert Suconic --- .dockerignore | 5 + .gitignore | 38 ++ .mvn/wrapper/.gitignore | 1 + .mvn/wrapper/MavenWrapperDownloader.java | 93 +++++ .mvn/wrapper/maven-wrapper.properties | 20 ++ LICENSE | 222 ++---------- README.md | 2 +- control/pom.xml | 105 ++++++ .../scenarios/model/requests/BaseRequest.java | 91 +++++ .../requests/BusinessProcessRequest.java | 45 +++ .../model/requests/OrdersIncomeRequest.java | 65 ++++ .../model/response/BaseResponse.java | 32 ++ .../model/response/OrdersResponse.java | 32 ++ .../scenarios/service/BaseListener.java | 65 ++++ .../scenarios/service/BaseService.java | 46 +++ .../scenarios/service/BusinessService.java | 82 +++++ .../scenarios/service/IncomeService.java | 60 ++++ .../service/business/DelivererBusiness.java | 53 +++ .../business/DeliveryRouteBusiness.java | 59 ++++ .../business/ManufactureRouterBusiness.java | 53 +++ .../business/ProductionLineBusiness.java | 56 +++ .../scenarios/test/ValidateProcessTest.java | 153 ++++++++ .../src/test/resources/RequiredDiverts.txt | 62 ++++ docs/BusinessDelivery.adoc | 45 +++ mvnw | 332 ++++++++++++++++++ mvnw.cmd | 206 +++++++++++ pom.xml | 85 +++++ quarkus-app/README.md | 63 ++++ .../requests/example-scenario-queue.yaml | 51 +++ .../requests/example-scenario-tempqueue.yaml | 49 +++ quarkus-app/pom.xml | 145 ++++++++ quarkus-app/src/main/docker/Dockerfile.jvm | 97 +++++ .../src/main/docker/Dockerfile.legacy-jar | 93 +++++ quarkus-app/src/main/docker/Dockerfile.native | 27 ++ .../src/main/docker/Dockerfile.native-micro | 30 ++ .../artemis/scenarios/resource/Constants.java | 26 ++ .../resource/IncomeOrdersResource.java | 30 ++ .../scenarios/resource/ProcessResource.java | 30 ++ .../src/main/resources/application.properties | 5 + 39 files changed, 2552 insertions(+), 202 deletions(-) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 .mvn/wrapper/.gitignore create mode 100644 .mvn/wrapper/MavenWrapperDownloader.java create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 control/pom.xml create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BaseRequest.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BusinessProcessRequest.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/OrdersIncomeRequest.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/BaseResponse.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/OrdersResponse.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseListener.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseService.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/BusinessService.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/IncomeService.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DelivererBusiness.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DeliveryRouteBusiness.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ManufactureRouterBusiness.java create mode 100644 control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ProductionLineBusiness.java create mode 100644 control/src/test/java/org/apache/activemq/artemis/scenarios/test/ValidateProcessTest.java create mode 100644 control/src/test/resources/RequiredDiverts.txt create mode 100644 docs/BusinessDelivery.adoc create mode 100755 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 quarkus-app/README.md create mode 100644 quarkus-app/examples/requests/example-scenario-queue.yaml create mode 100644 quarkus-app/examples/requests/example-scenario-tempqueue.yaml create mode 100644 quarkus-app/pom.xml create mode 100644 quarkus-app/src/main/docker/Dockerfile.jvm create mode 100644 quarkus-app/src/main/docker/Dockerfile.legacy-jar create mode 100644 quarkus-app/src/main/docker/Dockerfile.native create mode 100644 quarkus-app/src/main/docker/Dockerfile.native-micro create mode 100644 quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/Constants.java create mode 100644 quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/IncomeOrdersResource.java create mode 100644 quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/ProcessResource.java create mode 100644 quarkus-app/src/main/resources/application.properties diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2fcdf8a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-scenarioRequest/* \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ced9bd0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +#Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +release.properties +.flattened-pom.xml + +# IntelliJ +*.ipr +*.iml +*.iws + +# Visual Studio Code +.vscode +.factorypath + +# OSX +.DS_Store + +# Vim +*.swp +*.swo + +# patch +*.orig +*.rej + +# Local environment +.env + +# Plugin directory +/.quarkus/cli/plugins/ +# TLS Certificates +.certs/ + +# tmp +/tmp/ diff --git a/.mvn/wrapper/.gitignore b/.mvn/wrapper/.gitignore new file mode 100644 index 0000000..e72f5e8 --- /dev/null +++ b/.mvn/wrapper/.gitignore @@ -0,0 +1 @@ +maven-wrapper.jar diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100644 index 0000000..fe7d037 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.IOException; +import java.io.InputStream; +import java.net.Authenticator; +import java.net.PasswordAuthentication; +import java.net.URI; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.concurrent.ThreadLocalRandom; + +public final class MavenWrapperDownloader { + private static final String WRAPPER_VERSION = "3.3.2"; + + private static final boolean VERBOSE = Boolean.parseBoolean(System.getenv("MVNW_VERBOSE")); + + public static void main(String[] args) { + log("Apache Maven Wrapper Downloader " + WRAPPER_VERSION); + + if (args.length != 2) { + System.err.println(" - ERROR wrapperUrl or wrapperJarPath parameter missing"); + System.exit(1); + } + + try { + log(" - Downloader started"); + final URL wrapperUrl = URI.create(args[0]).toURL(); + final String jarPath = args[1].replace("..", ""); // Sanitize path + final Path wrapperJarPath = Paths.get(jarPath).toAbsolutePath().normalize(); + downloadFileFromURL(wrapperUrl, wrapperJarPath); + log("Done"); + } catch (IOException e) { + System.err.println("- Error downloading: " + e.getMessage()); + if (VERBOSE) { + e.printStackTrace(); + } + System.exit(1); + } + } + + private static void downloadFileFromURL(URL wrapperUrl, Path wrapperJarPath) + throws IOException { + log(" - Downloading to: " + wrapperJarPath); + if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { + final String username = System.getenv("MVNW_USERNAME"); + final char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); + Authenticator.setDefault(new Authenticator() { + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + } + Path temp = wrapperJarPath + .getParent() + .resolve(wrapperJarPath.getFileName() + "." + + Long.toUnsignedString(ThreadLocalRandom.current().nextLong()) + ".tmp"); + try (InputStream inStream = wrapperUrl.openStream()) { + Files.copy(inStream, temp, StandardCopyOption.REPLACE_EXISTING); + Files.move(temp, wrapperJarPath, StandardCopyOption.REPLACE_EXISTING); + } finally { + Files.deleteIfExists(temp); + } + log(" - Downloader complete"); + } + + private static void log(String msg) { + if (VERBOSE) { + System.out.println(msg); + } + } + +} diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..72df6c6 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=source +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.8/apache-maven-3.9.8-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar \ No newline at end of file diff --git a/LICENSE b/LICENSE index 261eeb9..bf88b35 100644 --- a/LICENSE +++ b/LICENSE @@ -1,201 +1,21 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. +MIT License + +Copyright (c) 2024 Tiago Bueno + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 7a21675..ff1babe 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # artemis-scenarios -A ActiveMQ Artemis Application Scenario +A ActiveMQ Artemis Application to exercise Artemis features diff --git a/control/pom.xml b/control/pom.xml new file mode 100644 index 0000000..8dcc4b1 --- /dev/null +++ b/control/pom.xml @@ -0,0 +1,105 @@ + + + 4.0.0 + + + org.apache.activemq.artemis + scenarios-project + 1.0-SNAPSHOT + + + control + jar + ActiveMQ Scenarios Control + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + unpack-artemis + compile + + unpack + + + + + org.apache.activemq + apache-artemis + ${artemis.version} + bin + zip + ${basedir}/target/artemis-release + + + + + + + + + + + + org.apache.qpid + qpid-jms-client + + + org.apache.activemq + artemis-jms-client-all + + + org.apache.activemq + artemis-cli + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + \ No newline at end of file diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BaseRequest.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BaseRequest.java new file mode 100644 index 0000000..3d4045f --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BaseRequest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.model.requests; + +import java.util.Objects; + +public class BaseRequest { + String protocol; + String uri; + + String user; + + String password; + + public String getProtocol() { + return protocol; + } + + public BaseRequest setProtocol(String protocol) { + this.protocol = protocol; + return this; + } + + public String getUser() { + return user; + } + + public BaseRequest setUser(String user) { + this.user = user; + return this; + } + + public String getPassword() { + return password; + } + + public BaseRequest setPassword(String password) { + this.password = password; + return this; + } + + public String getUri() { + return uri; + } + + public BaseRequest setUri(String uri) { + this.uri = uri; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + BaseRequest that = (BaseRequest) o; + + if (!Objects.equals(protocol, that.protocol)) + return false; + return Objects.equals(uri, that.uri); + } + + @Override + public int hashCode() { + int result = protocol != null ? protocol.hashCode() : 0; + result = 31 * result + (uri != null ? uri.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "BaseRequest{" + "protocol='" + protocol + '\'' + ", uri='" + uri + '\'' + '}'; + } +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BusinessProcessRequest.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BusinessProcessRequest.java new file mode 100644 index 0000000..41ca991 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/BusinessProcessRequest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.model.requests; + +import javax.jms.Connection; + +public class BusinessProcessRequest extends BaseRequest { + int connections; + + // TODO remove this + int elements; + + public int getElements() { + return elements; + } + + public BusinessProcessRequest setElements(int elements) { + this.elements = elements; + return this; + } + + public int getConnections() { + return connections; + } + + public BusinessProcessRequest setConnections(int connections) { + this.connections = connections; + return this; + } +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/OrdersIncomeRequest.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/OrdersIncomeRequest.java new file mode 100644 index 0000000..6c1e528 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/requests/OrdersIncomeRequest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.model.requests; + +public class OrdersIncomeRequest extends BaseRequest { + int numberOfOrders; + int commitInterval; + + public int getNumberOfOrders() { + return numberOfOrders; + } + + public OrdersIncomeRequest setNumberOfOrders(int numberOfOrders) { + this.numberOfOrders = numberOfOrders; + return this; + } + + public int getCommitInterval() { + return commitInterval; + } + + public OrdersIncomeRequest setCommitInterval(int commitInterval) { + this.commitInterval = commitInterval; + return this; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + if (!super.equals(o)) + return false; + + OrdersIncomeRequest that = (OrdersIncomeRequest) o; + + if (numberOfOrders != that.numberOfOrders) + return false; + return commitInterval == that.commitInterval; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + numberOfOrders; + result = 31 * result + commitInterval; + return result; + } +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/BaseResponse.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/BaseResponse.java new file mode 100644 index 0000000..720dd2a --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/BaseResponse.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.model.response; + +public class BaseResponse { + + boolean ok; + + public boolean isOk() { + return ok; + } + + public BaseResponse setOk(boolean ok) { + this.ok = ok; + return this; + } +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/OrdersResponse.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/OrdersResponse.java new file mode 100644 index 0000000..e2ad70c --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/model/response/OrdersResponse.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.model.response; + +public class OrdersResponse { + + int numberOfOrders; + + public int getNumberOfOrders() { + return numberOfOrders; + } + + public OrdersResponse setNumberOfOrders(int numberOfOrders) { + this.numberOfOrders = numberOfOrders; + return this; + } +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseListener.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseListener.java new file mode 100644 index 0000000..d0d7a33 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseListener.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service; + +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import javax.jms.Session; + +public abstract class BaseListener implements MessageListener { + + protected final Session session; + protected final MessageConsumer consumer; + + protected MessageProducer producer = null; + + + @Override + public void onMessage(Message message) { + try { + if (producer == null) { + producer = createProducer(); + } + + message = processMessage(message); + + producer.send(message); + session.commit(); + } catch (Exception e) { + e.printStackTrace(); + try { + session.rollback(); + } catch (Throwable e2) { + e.printStackTrace(); + } + } + } + protected abstract MessageProducer createProducer() throws Exception; + + public BaseListener(Session session, MessageConsumer consumer) throws Exception { + this.session = session; + this.consumer = consumer; + } + + protected Message processMessage(Message message) { + return message; + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseService.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseService.java new file mode 100644 index 0000000..04b427d --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BaseService.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service; + +import javax.jms.ConnectionFactory; + +import org.apache.qpid.jms.JmsConnectionFactory; + +public class BaseService { + + + public static ConnectionFactory createConnectionFactory(String protocol, String uri) { + if (protocol.toUpperCase().equals("OPENWIRE")) { + throw new RuntimeException("not implemented yet"); + //return new org.apache.activemq.ActiveMQConnectionFactory(uri); + } else if (protocol.toUpperCase().equals("AMQP")) { + + if (uri.startsWith("tcp://")) { + // replacing tcp:// by amqp:// + uri = "amqp" + uri.substring(3); + } + return new JmsConnectionFactory(uri); + } else if (protocol.toUpperCase().equals("CORE") || protocol.toUpperCase().equals("ARTEMIS")) { + return new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory(uri); + } else { + throw new IllegalStateException("Unknown:" + protocol); + } + } + + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BusinessService.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BusinessService.java new file mode 100644 index 0000000..3b69a65 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/BusinessService.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.activemq.artemis.scenarios.model.requests.BusinessProcessRequest; +import org.apache.activemq.artemis.scenarios.model.response.BaseResponse; +import org.apache.activemq.artemis.scenarios.service.business.DelivererBusiness; +import org.apache.activemq.artemis.scenarios.service.business.DeliveryRouteBusiness; +import org.apache.activemq.artemis.scenarios.service.business.ManufactureRouterBusiness; +import org.apache.activemq.artemis.scenarios.service.business.ProductionLineBusiness; + +public class BusinessService extends BaseService { + + + Connection[] connections; + Connection[] topicConnections; + + public void startConnections(BusinessProcessRequest bpRequest) throws Exception { + connections = new Connection[bpRequest.getConnections()]; + ConnectionFactory cf = createConnectionFactory(bpRequest.getProtocol(), bpRequest.getUri()); + for (int i = 0; i < connections.length; i++) { + connections[i] = cf.createConnection(bpRequest.getUser(), bpRequest.getPassword()); + ManufactureRouterBusiness.configureListener(connections[i]); + ProductionLineBusiness.configureListener(connections[i]); + DelivererBusiness.configureListener(connections[i]); + DeliveryRouteBusiness.configureListener(connections[i]); + } + } + + public void closeConnections() throws Exception { + for (Connection c: connections) { + c.close(); + } + connections = null; + } + + public BaseResponse process(BusinessProcessRequest bpRequest) throws Exception { + ConnectionFactory cf = createConnectionFactory(bpRequest.getProtocol(), bpRequest.getUri()); + + try (Connection connection = cf.createConnection(bpRequest.getUser(), bpRequest.getPassword())) { + + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer consumer = session.createConsumer(session.createQueue("IncomeOrder")); + MessageProducer producer = session.createProducer(session.createQueue("Manufacturing")); + connection.start(); + for (int i = 0; i < bpRequest.getElements(); i++) { + Message message = consumer.receive(5000); + if (message != null) { + System.out.println(message); + producer.send(message); + } + } + + session.commit(); + } + + return new BaseResponse().setOk(true); + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/IncomeService.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/IncomeService.java new file mode 100644 index 0000000..df7e7ce --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/IncomeService.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.activemq.artemis.scenarios.model.requests.OrdersIncomeRequest; +import org.apache.activemq.artemis.scenarios.model.response.OrdersResponse; +import org.apache.activemq.artemis.utils.RandomUtil; + +public class IncomeService extends BaseService { + + public OrdersResponse process(OrdersIncomeRequest income) throws Exception { + ConnectionFactory factory = createConnectionFactory(income.getProtocol(), income.getUri()); + + try (Connection connection = factory.createConnection(income.getUser(), income.getPassword())) { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + + MessageProducer producer = session.createProducer(session.createQueue("IncomeOrder")); + int productID = 0; + + for (int i = 0; i < income.getNumberOfOrders(); i++) { + TextMessage message = session.createTextMessage("this is a test " + i); + message.setIntProperty("productID", productID); + message.setIntProperty("quantity", RandomUtil.randomInterval(1, 30)); + message.setIntProperty("zipCode", RandomUtil.randomInterval(1, 100)); + producer.send(message); + if (++productID >= 10) { + productID = 0; + } + } + + session.commit(); + } + + + return new OrdersResponse().setNumberOfOrders(income.getNumberOfOrders()); + + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DelivererBusiness.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DelivererBusiness.java new file mode 100644 index 0000000..bdd9f1c --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DelivererBusiness.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service.business; + +import javax.jms.Connection; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.activemq.artemis.scenarios.service.BaseListener; + +public class DelivererBusiness { + + public static final String OUTPUT_ADDRESS = "DeliveryRoutes"; + public static final String INCOME_ADDRESS = "ProductionCompletion"; + + public static void configureListener(Connection connection) throws Exception { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer consumer = session.createConsumer(session.createQueue(INCOME_ADDRESS)); + Listener listener = new Listener(session, consumer); + consumer.setMessageListener(listener); + connection.start(); + } + + + private static class Listener extends BaseListener { + + Listener(Session session, MessageConsumer consumer) throws Exception { + super(session, consumer); + } + + protected MessageProducer createProducer() throws Exception { + return session.createProducer(session.createTopic(OUTPUT_ADDRESS)); + } + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DeliveryRouteBusiness.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DeliveryRouteBusiness.java new file mode 100644 index 0000000..d02045e --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/DeliveryRouteBusiness.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service.business; + +import javax.jms.Connection; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.Topic; + +import org.apache.activemq.artemis.scenarios.service.BaseListener; + +public class DeliveryRouteBusiness { + + public static final String OUTPUT_ADDRESS = "Delivered"; + public static final String INCOME_ADDRESS = "DeliveryRoutes"; + + public static void configureListener(Connection connection) throws Exception { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + + Topic topic = session.createTopic(INCOME_ADDRESS); + + for (int i = 0; i < 10; i++) { + MessageConsumer consumer = session.createSharedDurableConsumer(topic, "route" + i, "zipCode > " + (i * 10) + "AND zipCode <= " + (i * 10 + 10)); + Listener listener = new Listener(session, consumer); + consumer.setMessageListener(listener); + connection.start(); + } + } + + + private static class Listener extends BaseListener { + + Listener(Session session, MessageConsumer consumer) throws Exception { + super(session, consumer); + } + + protected MessageProducer createProducer() throws Exception { + return session.createProducer(session.createQueue(OUTPUT_ADDRESS)); + } + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ManufactureRouterBusiness.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ManufactureRouterBusiness.java new file mode 100644 index 0000000..246ee63 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ManufactureRouterBusiness.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service.business; + +import javax.jms.Connection; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.activemq.artemis.scenarios.service.BaseListener; + +public class ManufactureRouterBusiness { + + public static final String OUTPUT_ADDRESS = "Manufacturing"; + public static final String INCOME_ADDRESS = "IncomeOrder"; + + public static void configureListener(Connection connection) throws Exception { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + MessageConsumer consumer = session.createConsumer(session.createQueue(INCOME_ADDRESS)); + Listener listener = new Listener(session, consumer); + consumer.setMessageListener(listener); + connection.start(); + } + + + private static class Listener extends BaseListener { + Listener(Session session, MessageConsumer consumer) throws Exception { + super(session, consumer); + } + + protected MessageProducer createProducer() throws Exception { + return session.createProducer(session.createQueue(OUTPUT_ADDRESS)); + } + + } + +} diff --git a/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ProductionLineBusiness.java b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ProductionLineBusiness.java new file mode 100644 index 0000000..b3fd2f3 --- /dev/null +++ b/control/src/main/java/org/apache/activemq/artemis/scenarios/service/business/ProductionLineBusiness.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.service.business; + +import javax.jms.Connection; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; + +import org.apache.activemq.artemis.scenarios.service.BaseListener; + +public class ProductionLineBusiness { + + public static final String OUTPUT_ADDRESS = "ProductionCompletion"; + public static final String INCOME_ADDRESS = "Manufacturing.Line"; + + public static void configureListener(Connection connection) throws Exception { + Session session = connection.createSession(true, Session.SESSION_TRANSACTED); + + for (int i = 0; i < 10; i++) { + MessageConsumer consumer = session.createConsumer(session.createQueue(INCOME_ADDRESS + i)); + Listener listener = new Listener(session, consumer); + consumer.setMessageListener(listener); + connection.start(); + } + } + + + private static class Listener extends BaseListener { + + Listener(Session session, MessageConsumer consumer) throws Exception { + super(session, consumer); + } + + protected MessageProducer createProducer() throws Exception { + return session.createProducer(session.createQueue(OUTPUT_ADDRESS)); + } + } + +} diff --git a/control/src/test/java/org/apache/activemq/artemis/scenarios/test/ValidateProcessTest.java b/control/src/test/java/org/apache/activemq/artemis/scenarios/test/ValidateProcessTest.java new file mode 100644 index 0000000..d37c72d --- /dev/null +++ b/control/src/test/java/org/apache/activemq/artemis/scenarios/test/ValidateProcessTest.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.test; + +import java.io.File; +import java.util.concurrent.TimeUnit; + +import org.apache.activemq.artemis.api.core.management.SimpleManagement; +import org.apache.activemq.artemis.cli.commands.helper.HelperCreate; +import org.apache.activemq.artemis.scenarios.model.requests.BusinessProcessRequest; +import org.apache.activemq.artemis.scenarios.model.requests.OrdersIncomeRequest; +import org.apache.activemq.artemis.scenarios.service.BusinessService; +import org.apache.activemq.artemis.scenarios.service.IncomeService; +import org.apache.activemq.artemis.scenarios.service.business.DeliveryRouteBusiness; +import org.apache.activemq.artemis.scenarios.service.business.ManufactureRouterBusiness; +import org.apache.activemq.artemis.util.ServerUtil; +import org.apache.activemq.artemis.utils.FileUtil; +import org.apache.activemq.artemis.utils.Waiter; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ValidateProcessTest { + + // Set this to false if you want to create and start your own server + public static final boolean CREATE_SERVERS = Boolean.parseBoolean(System.getProperty("ValidateProcessTest.createServers", "true")); + + public static final String ORDERS_INCOME_REQUEST_URI = System.getProperty("ValidateProcessTest.ordersIncomeRequest", "tcp://localhost:61616"); + public static final String BUSINESS_PROCESS_REQUEST_URI = System.getProperty("ValidateProcessTest.businessProcessRequest", "tcp://localhost:61616"); + public static final String SIMPLE_MANAGEMENT_URI = System.getProperty("ValidateProcessTest.simpleManagement", "tcp://localhost:61616"); + + + // Set this to true if you want to enable tracing on the server + public static final boolean TRACE_LOGS = false; + + private static final String DIVERT_CONFIGURATION = "RequiredDiverts.txt"; + + private static final String HOME_LOCATION = "./target/artemis-release/apache-artemis-2.39.0-SNAPSHOT"; + private static final String SERVER_NAME = "myServer"; + private static final File ARTEMIS_INSTANCE = new File("./target/" + SERVER_NAME); + + private Process serverProcess; + + private static String QUEUE_LIST = "ProductionCompletion,IncomeOrder,Manufacturing.Line0,Manufacturing.Line1,Manufacturing.Line2,Manufacturing.Line3,Manufacturing.Line4,Manufacturing.Line5,Manufacturing.Line6,Manufacturing.Line7,Manufacturing.Line8,Manufacturing.Line9"; + private static String ADDRESS_LIST = "DeliveryRoutes"; + + @BeforeAll + public static void createServer() throws Exception { + if (!CREATE_SERVERS) { + return; + } + FileUtil.deleteDirectory(ARTEMIS_INSTANCE); + + HelperCreate cliCreateServer = new HelperCreate(new File(HOME_LOCATION)); + cliCreateServer.setArtemisInstance(ARTEMIS_INSTANCE); + cliCreateServer.addArgs("--queues", QUEUE_LIST); + cliCreateServer.addArgs("--addresses", ADDRESS_LIST); + cliCreateServer.setNoWeb(false); + cliCreateServer.createServer(); + + + String divertConfig = FileUtil.readFile(ValidateProcessTest.class.getClassLoader().getResourceAsStream(DIVERT_CONFIGURATION)); + assertNotNull(divertConfig); + File brokerXML = new File(ARTEMIS_INSTANCE, "/etc/broker.xml"); + assertTrue(FileUtil.findReplace(brokerXML, "", "\n" + divertConfig)); + + if (TRACE_LOGS) { + replaceLogs(ARTEMIS_INSTANCE); + } + } + + private static void replaceLogs(File serverLocation) throws Exception { + File log4j = new File(serverLocation, "/etc/log4j2.properties"); + assertTrue(FileUtil.findReplace(log4j, "logger.artemis_utils.level=INFO", "logger.artemis_utils.level=INFO\n" + "\n" + "logger.divert.name=org.apache.activemq.artemis.core.server.impl.DivertImpl\nlogger.divert.level=TRACE")); + } + + @BeforeEach + public void startProcess() throws Exception { + if (CREATE_SERVERS) { + File dataDirectory = new File(ARTEMIS_INSTANCE, "./data"); + FileUtil.deleteDirectory(dataDirectory); + serverProcess = ServerUtil.startServer("./target/myServer", "myServer"); + ServerUtil.waitForServerToStart(0, 5000); + } + } + + @AfterEach + public void killProcess() throws Throwable { + if (CREATE_SERVERS) { + serverProcess.destroyForcibly(); + serverProcess.waitFor(); + serverProcess = null; + } + } + + @Test + public void testConnections() throws Exception { + int nElements = 1_000; + OrdersIncomeRequest ordersIncomeRequest = new OrdersIncomeRequest(); + ordersIncomeRequest.setNumberOfOrders(nElements).setCommitInterval(100).setUri(ORDERS_INCOME_REQUEST_URI).setProtocol("CORE"); + + BusinessProcessRequest businessProcessRequest = new BusinessProcessRequest(); + businessProcessRequest.setUri(BUSINESS_PROCESS_REQUEST_URI).setProtocol("CORE"); + + businessProcessRequest.setElements(nElements).setConnections(10); + + BusinessService manufacturingRouteService = new BusinessService(); + manufacturingRouteService.startConnections(businessProcessRequest); + + IncomeService incomeService = new IncomeService(); + incomeService.process(ordersIncomeRequest); + + SimpleManagement simpleManagement = new SimpleManagement(SIMPLE_MANAGEMENT_URI, null, null); + + validateMessageCount(simpleManagement, ManufactureRouterBusiness.INCOME_ADDRESS, 0); + validateMessageCount(simpleManagement, DeliveryRouteBusiness.OUTPUT_ADDRESS, nElements); + + manufacturingRouteService.closeConnections(); + } + + private static void validateMessageCount(SimpleManagement simpleManagement, String queue, int expectedCount) throws Exception { + Waiter.waitFor(() -> { + try { + return simpleManagement.getMessageCountOnQueue(queue) == expectedCount; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + }, TimeUnit.SECONDS, 300, TimeUnit.MILLISECONDS, 100); + + assertEquals(expectedCount, simpleManagement.getMessageCountOnQueue(queue)); + } +} diff --git a/control/src/test/resources/RequiredDiverts.txt b/control/src/test/resources/RequiredDiverts.txt new file mode 100644 index 0000000..262505f --- /dev/null +++ b/control/src/test/resources/RequiredDiverts.txt @@ -0,0 +1,62 @@ + + +
Manufacturing
+ Manufacturing.Line0 + + true +
+ +
Manufacturing
+ Manufacturing.Line1 + + true +
+ +
Manufacturing
+ Manufacturing.Line2 + + true +
+ +
Manufacturing
+ Manufacturing.Line3 + + true +
+ +
Manufacturing
+ Manufacturing.Line4 + + true +
+ +
Manufacturing
+ Manufacturing.Line5 + + true +
+ +
Manufacturing
+ Manufacturing.Line6 + + true +
+ +
Manufacturing
+ Manufacturing.Line7 + + true +
+ +
Manufacturing
+ Manufacturing.Line8 + + true +
+ +
Manufacturing
+ Manufacturing.Line9 + + true +
+
\ No newline at end of file diff --git a/docs/BusinessDelivery.adoc b/docs/BusinessDelivery.adoc new file mode 100644 index 0000000..e6ca9a8 --- /dev/null +++ b/docs/BusinessDelivery.adoc @@ -0,0 +1,45 @@ += Business Solution + +This application simulates an internet shop delivery. Income orders are generated from an external system and we must route the packages accordingly. + +Queues used in this application + + +- IncomeOrder: +* User inputs an order +properties: +** productID = Integer (range 0 to 10) +** quantity = number of items (positive integer > 0 & <= 1000) +** customerID = not used for now +** zipCode = zip code for the customer (between 1 and 100) + + +- Manufacturing: +Address used to divert manufacturing lines + + +- Manufacturing.Line0 ~ Manufacturing.Line9 +** (10 Diverts, filtering with id = [0-9]) + +- ProductionCompletion + +- CustomerDeliveredEvent + + +- DeliveryRoutes: +* Topic with durable subscriptions to choose from the options. + + +- There will be 10 subscriptions: +* zipCode > 0 && <= 10 +* zipCode > 10 && <= 20 +* zipCode > 20 && <= 30 +.... +* zipCode > 90 && <= 100 + + + + +- Queue Delivered: + +Information that the queue Was delivered. diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..5e9618c --- /dev/null +++ b/mvnw @@ -0,0 +1,332 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ]; then + + if [ -f /usr/local/etc/mavenrc ]; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ]; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ]; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false +darwin=false +mingw=false +case "$(uname)" in +CYGWIN*) cygwin=true ;; +MINGW*) mingw=true ;; +Darwin*) + darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)" + export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home" + export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ]; then + if [ -r /etc/gentoo-release ]; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin; then + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] \ + && JAVA_HOME="$( + cd "$JAVA_HOME" || ( + echo "cannot cd into $JAVA_HOME." >&2 + exit 1 + ) + pwd + )" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin; then + javaHome="$(dirname "$javaExecutable")" + javaExecutable="$(cd "$javaHome" && pwd -P)/javac" + else + javaExecutable="$(readlink -f "$javaExecutable")" + fi + javaHome="$(dirname "$javaExecutable")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ]; then + if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$( + \unset -f command 2>/dev/null + \command -v java + )" + fi +fi + +if [ ! -x "$JAVACMD" ]; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ]; then + echo "Warning: JAVA_HOME environment variable is not set." >&2 +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ]; then + echo "Path not specified to find_maven_basedir" >&2 + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ]; do + if [ -d "$wdir"/.mvn ]; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$( + cd "$wdir/.." || exit 1 + pwd + ) + fi + # end of workaround + done + printf '%s' "$( + cd "$basedir" || exit 1 + pwd + )" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' <"$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1 +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in wrapperUrl) + wrapperUrl="$safeValue" + break + ;; + esac + done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget >/dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl >/dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in wrapperSha256Sum) + wrapperSha256Sum=$value + break + ;; + esac +done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c >/dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c >/dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] \ + && MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..4136715 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,206 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. >&2 +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. >&2 +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash;"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Error 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Error 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Error 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cbcc4b9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,85 @@ + + + + 4.0.0 + org.apache.activemq.artemis + scenarios-project + pom + 1.0-SNAPSHOT + + + 3.13.0 + 2.4.0 + 2.18.0 + 2.0.1.Final + 1.18.34 + UTF-8 + UTF-8 + 2.6.1 + quarkus-bom + io.quarkus.platform + 3.15.1 + true + 3.5.1 + 1.12.1 + 2.39.0-SNAPSHOT + 2.0.3 + 1.1.4 + 5.11.2 + + + + + + + org.apache.qpid + qpid-jms-client + ${qpid.jms.version} + + + org.apache.activemq + artemis-jms-client-all + ${artemis.version} + + + org.apache.activemq + artemis-cli + ${artemis.version} + + + + org.junit.jupiter + junit-jupiter-api + ${junit5.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + test + + + + + + quarkus-app + control + + + diff --git a/quarkus-app/README.md b/quarkus-app/README.md new file mode 100644 index 0000000..5b38abd --- /dev/null +++ b/quarkus-app/README.md @@ -0,0 +1,63 @@ +# artemis-scenarios + +This project uses Quarkus, the Supersonic Subatomic Java Framework. + +If you want to learn more about Quarkus, please visit its website: . + +## Running the application in dev mode + +You can run your application in dev mode that enables live coding using: + +```shell script +./mvnw compile quarkus:dev +``` + +> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at . + +## Packaging and running the application + +The application can be packaged using: + +```shell script +./mvnw package +``` + +It produces the `quarkus-run.jar` file in the `target/quarkus-scenarioRequest/` directory. +Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-scenarioRequest/lib/` directory. + +The application is now runnable using `java -jar target/quarkus-scenarioRequest/quarkus-run.jar`. + +If you want to build an _über-jar_, execute the following command: + +```shell script +./mvnw package -Dquarkus.package.jar.type=uber-jar +``` + +The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. + +## Creating a native executable + +You can create a native executable using: + +```shell script +./mvnw package -Dnative +``` + +Or, if you don't have GraalVM installed, you can run the native executable build in a container using: + +```shell script +./mvnw package -Dnative -Dquarkus.native.container-build=true +``` + +You can then execute your native executable with: `./target/artemis-scenarios-1.0-SNAPSHOT-runner` + +If you want to learn more about building native executables, please consult . + +## Related Guides + +- REST ([guide](https://quarkus.io/guides/rest)): A Jakarta REST implementation utilizing build time processing and Vert.x. This extension is not compatible with the quarkus-resteasy extension, or any of the extensions that depend on it. + + +## Deployments + +In the [deployments](deployments) directory there are tools to help in the deployment of artemis on kubernetes. Please check the [deployments README file](deployments/README.md) \ No newline at end of file diff --git a/quarkus-app/examples/requests/example-scenario-queue.yaml b/quarkus-app/examples/requests/example-scenario-queue.yaml new file mode 100644 index 0000000..45bf2ec --- /dev/null +++ b/quarkus-app/examples/requests/example-scenario-queue.yaml @@ -0,0 +1,51 @@ +destinationClass: jakarta.jms.Queue +destinationName: myTestQueue1 +replyDestinationClass: jakarta.jms.Queue +replyDestinationName: myTestReplyQueue1 +sources: + - id: source-app-1 + enabled: true + producers: + - id: producer-1 + enabled: true + connection: + url: failover:(amqp://single.localcluster:51511) + username: admin + password: admin + numOfConnections: 2 # will create a thread for each connection + numOfSessionsPerConnection: 5 # will create a thread for each session on each connection thread + session: + sessionAckMode: 0 # 0 = SESSION_TRANSACTED, 1 = AUTO_ACKNOWLEDGE, 2 = CLIENT_ACKNOWLEDGE and 3 = DUPS_OK_ACKNOWLEDGE + transactedSession: true + message: + numOfMsgPerSession: 1000 # -1 for keep producing forever + msgSizeInKb: 100 + commitOnEveryXMsgs: 1 + delayBetweenMsgs: 0 + setReplyDestination: true + deliveryMode: 2 # 1 = NON_PERSISTENT, 2 = PERSISTENT + msgProperties: + # - key: + # value: +targets: + - id: target-app-1 + enabled: true + consumers: + - id: consumer-1 + enabled: true + connection: + url: failover:(amqp://single.localcluster:51511) + username: admin + password: admin + numOfConnections: 2 # will create a thread for each connection + numOfSessionsPerConnection: 5 # will create a thread for each session on each connection thread + session: + sessionAckMode: 0 # 0 = SESSION_TRANSACTED, 1 = AUTO_ACKNOWLEDGE, 2 = CLIENT_ACKNOWLEDGE and 3 = DUPS_OK_ACKNOWLEDGE + transactedSession: true + message: + numOfMsgPerSession: 1000 # -1 for keep consuming forever + msgTimeoutInMs: -1 # -1 for wait forever + commitOnEveryXMsgs: 1 + delayBetweenMsgs: 0 + sendReply: true # Consume and send reply back + msgSelector: diff --git a/quarkus-app/examples/requests/example-scenario-tempqueue.yaml b/quarkus-app/examples/requests/example-scenario-tempqueue.yaml new file mode 100644 index 0000000..5561ed6 --- /dev/null +++ b/quarkus-app/examples/requests/example-scenario-tempqueue.yaml @@ -0,0 +1,49 @@ +destinationClass: jakarta.jms.TemporaryQueue +replyDestinationClass: jakarta.jms.TemporaryQueue +sources: + - id: source-app-1 + enabled: true + producers: + - id: producer-1 + enabled: true + connection: + url: failover:(amqp://single.localcluster:51511) + username: admin + password: admin + numOfConnections: 2 # will create a thread for each connection + numOfSessionsPerConnection: 5 # will create a thread for each session on each connection thread + session: + sessionAckMode: 0 # 0 = SESSION_TRANSACTED, 1 = AUTO_ACKNOWLEDGE, 2 = CLIENT_ACKNOWLEDGE and 3 = DUPS_OK_ACKNOWLEDGE + transactedSession: true + message: + numOfMsgPerSession: 1000 # -1 for keep producing forever + msgSizeInKb: 100 + commitOnEveryXMsgs: 1 + delayBetweenMsgs: 0 + setReplyDestination: true + deliveryMode: 2 # 1 = NON_PERSISTENT, 2 = PERSISTENT + msgProperties: + # - key: + # value: +targets: + - id: target-app-1 + enabled: true + consumers: + - id: consumer-1 + enabled: true + connection: + url: failover:(amqp://single.localcluster:51511) + username: admin + password: admin + numOfConnections: 2 # will create a thread for each connection + numOfSessionsPerConnection: 5 # will create a thread for each session on each connection thread + session: + sessionAckMode: 0 # 0 = SESSION_TRANSACTED, 1 = AUTO_ACKNOWLEDGE, 2 = CLIENT_ACKNOWLEDGE and 3 = DUPS_OK_ACKNOWLEDGE + transactedSession: true + message: + numOfMsgPerSession: 1000 # -1 for keep consuming forever + msgTimeoutInMs: -1 # -1 for wait forever + commitOnEveryXMsgs: 1 + delayBetweenMsgs: 0 + sendReply: true # Consume and send reply back + msgSelector: diff --git a/quarkus-app/pom.xml b/quarkus-app/pom.xml new file mode 100644 index 0000000..2ee655c --- /dev/null +++ b/quarkus-app/pom.xml @@ -0,0 +1,145 @@ + + + 4.0.0 + + scenarios-app + + + org.apache.activemq.artemis + scenarios-project + 1.0-SNAPSHOT + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + com.fasterxml.jackson.jakarta.rs + jackson-jakarta-rs-yaml-provider + ${jackson-jakarta-rs-yaml-provider.version} + + + org.apache.activemq.artemis + control + ${project.version} + + + io.quarkiverse.messaginghub + quarkus-pooled-jms + 2.6.0 + + + io.quarkus + quarkus-rest + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit5 + test + + + net.datafaker + datafaker + ${datafaker.version} + + + org.apache.qpid + qpid-jms-client + ${qpid-jms-client.version} + + + org.jboss.logmanager + log4j2-jboss-logmanager + ${log4j2-jboss-logmanager.version} + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + + org.jboss.logmanager.LogManager + + + + + + + + + native + + + native + + + + false + true + + + + diff --git a/quarkus-app/src/main/docker/Dockerfile.jvm b/quarkus-app/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..d2155c5 --- /dev/null +++ b/quarkus-app/src/main/docker/Dockerfile.jvm @@ -0,0 +1,97 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/artemis-scenarios-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi8/openjdk-21:1.20 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-scenarioRequest/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-scenarioRequest/*.jar /deployments/ +COPY --chown=185 target/quarkus-scenarioRequest/scenarioRequest/ /deployments/scenarioRequest/ +COPY --chown=185 target/quarkus-scenarioRequest/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/quarkus-app/src/main/docker/Dockerfile.legacy-jar b/quarkus-app/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..b0bfe29 --- /dev/null +++ b/quarkus-app/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,93 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/artemis-scenarios-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi8/openjdk-21:1.20 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/quarkus-app/src/main/docker/Dockerfile.native b/quarkus-app/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..85ba42d --- /dev/null +++ b/quarkus-app/src/main/docker/Dockerfile.native @@ -0,0 +1,27 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/artemis-scenarios . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-app/src/main/docker/Dockerfile.native-micro b/quarkus-app/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..5370d28 --- /dev/null +++ b/quarkus-app/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,30 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/artemis-scenarios . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/artemis-scenarios +# +### +FROM quay.io/quarkus/quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/Constants.java b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/Constants.java new file mode 100644 index 0000000..4c07dac --- /dev/null +++ b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/Constants.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.activemq.artemis.scenarios.resource; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class Constants { + + public static final String APPLICATION_YAML = "application/yaml"; +} diff --git a/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/IncomeOrdersResource.java b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/IncomeOrdersResource.java new file mode 100644 index 0000000..f683380 --- /dev/null +++ b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/IncomeOrdersResource.java @@ -0,0 +1,30 @@ +package org.apache.activemq.artemis.scenarios.resource; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Response; +import org.apache.activemq.artemis.scenarios.model.requests.OrdersIncomeRequest; +import org.apache.activemq.artemis.scenarios.model.response.OrdersResponse; +import org.apache.activemq.artemis.scenarios.service.IncomeService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import static org.apache.activemq.artemis.scenarios.resource.Constants.APPLICATION_YAML; + +@Path("/incomeOrders") +public class IncomeOrdersResource { + + private static final Logger LOGGER = LogManager.getLogger(IncomeOrdersResource.class); + + @POST + @Consumes(APPLICATION_YAML) + @Produces(APPLICATION_YAML) + public Response startScenario(OrdersIncomeRequest scenarioRequest) throws Exception { + IncomeService incomeService = new IncomeService(); + OrdersResponse result = incomeService.process(scenarioRequest); + + return Response.ok(result).build(); + } +} diff --git a/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/ProcessResource.java b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/ProcessResource.java new file mode 100644 index 0000000..2af79f8 --- /dev/null +++ b/quarkus-app/src/main/java/org/apache/activemq/artemis/scenarios/resource/ProcessResource.java @@ -0,0 +1,30 @@ +package org.apache.activemq.artemis.scenarios.resource; + +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.Response; +import org.apache.activemq.artemis.scenarios.model.requests.BusinessProcessRequest; +import org.apache.activemq.artemis.scenarios.model.response.BaseResponse; +import org.apache.activemq.artemis.scenarios.service.BusinessService; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import static org.apache.activemq.artemis.scenarios.resource.Constants.APPLICATION_YAML; + +@Path("/businessProcess") +public class ProcessResource { + + private static final Logger LOGGER = LogManager.getLogger(ProcessResource.class); + + @POST + @Consumes(APPLICATION_YAML) + @Produces(APPLICATION_YAML) + public Response startScenario(BusinessProcessRequest businessProcessRequest) throws Exception { + BusinessService service = new BusinessService(); + BaseResponse result = service.process(businessProcessRequest); + + return Response.ok(result).build(); + } +} diff --git a/quarkus-app/src/main/resources/application.properties b/quarkus-app/src/main/resources/application.properties new file mode 100644 index 0000000..2d19f92 --- /dev/null +++ b/quarkus-app/src/main/resources/application.properties @@ -0,0 +1,5 @@ +quarkus.index-dependency.yaml.group-id=com.fasterxml.jackson.jakarta.rs +quarkus.index-dependency.yaml.artifact-id=jackson-jakarta-rs-yaml-provider +quarkus.log.level=INFO +quarkus.log.category."org.apache.qpid".level=WARN +quarkus.log.category."org.apache.activemq.artemis.scenarios".level=INFO \ No newline at end of file