initial public commit
This commit is contained in:
201
system/core/events/events-handler/LICENSE.txt
Normal file
201
system/core/events/events-handler/LICENSE.txt
Normal file
@ -0,0 +1,201 @@
|
||||
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.
|
96
system/core/events/events-handler/pom.xml
Normal file
96
system/core/events/events-handler/pom.xml
Normal file
@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<groupId>ru.entaxy.esb.system.core.events</groupId>
|
||||
<artifactId>events</artifactId>
|
||||
<version>1.8.0</version>
|
||||
<relativePath>../../events/pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>events-handler</artifactId>
|
||||
<name>SYSTEM :: ENTAXY :: CORE :: EVENTS :: HANDLER</name>
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<properties>
|
||||
<bundle.osgi.import.pkg>
|
||||
org.apache.camel.component.jms,
|
||||
ru.entaxy.esb.system.core.events.jpa,
|
||||
ru.entaxy.esb.system.core.events.jpa.entity,
|
||||
ru.entaxy.esb.system.jpa.entity,
|
||||
com.google.gson.reflect,
|
||||
*
|
||||
</bundle.osgi.import.pkg>
|
||||
<camel-eventadmin.version>3.1.0</camel-eventadmin.version>
|
||||
<org.osgi.service.event.version>1.4.0</org.osgi.service.event.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>artemis-jms-client</artifactId>
|
||||
<version>${activemq.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.system.registry.systems</groupId>
|
||||
<artifactId>system-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.system.commons</groupId>
|
||||
<artifactId>system-commons</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.system.core.events</groupId>
|
||||
<artifactId>events-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ru.entaxy.esb.system.core.events</groupId>
|
||||
<artifactId>events-common</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-eventadmin</artifactId>
|
||||
<version>${camel-eventadmin.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-gson</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.service.event</artifactId>
|
||||
<version>${org.osgi.service.event.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,152 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.entaxy.esb.system.common.util.PropertiesHelper;
|
||||
import ru.entaxy.esb.system.core.events.handler.util.EventHelper;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
|
||||
import javax.jms.*;
|
||||
import java.util.List;
|
||||
|
||||
public class SubscriptionProcessingGenerator {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SubscriptionProcessingGenerator.class);
|
||||
|
||||
private EventHelper eventHelper;
|
||||
private PropertiesHelper propertiesHelper;
|
||||
private javax.jms.ConnectionFactory connectionFactory;
|
||||
|
||||
public void construct(Exchange exchange) throws Exception {
|
||||
List<SystemSubscription> subscriptions = (List<SystemSubscription>) exchange.getIn().getBody();
|
||||
|
||||
//consumer will created automatically with route
|
||||
// if (subscriptions != null && !subscriptions.isEmpty()) {
|
||||
// for (SystemSubscription subscription : subscriptions) {
|
||||
// LOG.debug("Prepare consumer topic: " + subscription.getEventTopic().getName() + " system: " + subscription.getSystem().getName());
|
||||
// createDurableConsumer(subscription);
|
||||
// }
|
||||
// }
|
||||
|
||||
SubscriptionRouteGenerator generator = new SubscriptionRouteGenerator(subscriptions, eventHelper, propertiesHelper);
|
||||
exchange.getContext().addRoutes(generator);
|
||||
}
|
||||
|
||||
private void createDurableConsumer(SystemSubscription subscription) throws JMSException {
|
||||
try (Connection conn = connectionFactory.createConnection()) {
|
||||
conn.setClientID(eventHelper.getClientId(subscription));
|
||||
|
||||
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
Topic topic = session.createTopic(subscription.getEventTopic().getName());
|
||||
|
||||
session.createDurableConsumer(topic, EventHelper.CONSUMER_NAME);
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void destruct(Exchange exchange) throws Exception {
|
||||
List<SystemSubscription> subscriptions = (List<SystemSubscription>) exchange.getIn().getBody();
|
||||
|
||||
boolean processRoute = exchange.getIn().getHeader("processRoute", false, Boolean.class);
|
||||
|
||||
if (processRoute) {
|
||||
SubscriptionRouteGenerator generator = new SubscriptionRouteGenerator(subscriptions, eventHelper, propertiesHelper);
|
||||
generator.deleteRoutes(exchange.getContext());
|
||||
}
|
||||
|
||||
if (subscriptions != null && !subscriptions.isEmpty()) {
|
||||
for (SystemSubscription subscription : subscriptions) {
|
||||
LOG.debug("Delete consumer topic: " + subscription.getEventTopic().getName() + " system " + subscription.getSystem().getName());
|
||||
purgeConsumerQueue(subscription);
|
||||
deleteConsumer(subscription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteConsumer(SystemSubscription subscription) throws JMSException {
|
||||
try (Connection conn = connectionFactory.createConnection()) {
|
||||
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
session.unsubscribe(eventHelper.getClientId(subscription));
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void purgeConsumerQueue(SystemSubscription subscription) throws JMSException {
|
||||
try (Connection conn = connectionFactory.createConnection()) {
|
||||
Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
|
||||
Topic topic = session.createTopic(subscription.getEventTopic().getName());
|
||||
MessageConsumer consumer = session.createSharedConsumer(topic, eventHelper.getClientId(subscription));
|
||||
|
||||
conn.start();
|
||||
|
||||
Message message = null;
|
||||
do {
|
||||
message = consumer.receive(500);
|
||||
} while (message != null);
|
||||
|
||||
conn.stop();
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
// public void constructRoute(Exchange exchange) throws Exception {
|
||||
// List<SystemSubscription> subscriptions = (List<SystemSubscription>) exchange.getIn().getBody();
|
||||
//
|
||||
// SubscriptionRouteGenerator generator = new SubscriptionRouteGenerator(subscriptions, eventHelper, propertiesHelper);
|
||||
// exchange.getContext().addRoutes(generator);
|
||||
// }
|
||||
|
||||
public void destructRoute(Exchange exchange) throws Exception {
|
||||
List<SystemSubscription> subscriptions = (List<SystemSubscription>) exchange.getIn().getBody();
|
||||
|
||||
SubscriptionRouteGenerator generator = new SubscriptionRouteGenerator(subscriptions, eventHelper, propertiesHelper);
|
||||
generator.deleteRoutes(exchange.getContext());
|
||||
}
|
||||
|
||||
public EventHelper getEventHelper() {
|
||||
return eventHelper;
|
||||
}
|
||||
|
||||
public void setEventHelper(EventHelper eventHelper) {
|
||||
this.eventHelper = eventHelper;
|
||||
}
|
||||
|
||||
public PropertiesHelper getPropertiesHelper() {
|
||||
return propertiesHelper;
|
||||
}
|
||||
|
||||
public void setPropertiesHelper(PropertiesHelper propertiesHelper) {
|
||||
this.propertiesHelper = propertiesHelper;
|
||||
}
|
||||
|
||||
public javax.jms.ConnectionFactory getConnectionFactory() {
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
public void setConnectionFactory(javax.jms.ConnectionFactory connectionFactory) {
|
||||
this.connectionFactory = connectionFactory;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.model.RouteDefinition;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.entaxy.esb.system.common.osgi.OSGIUtils;
|
||||
import ru.entaxy.esb.system.common.util.PropertiesHelper;
|
||||
import ru.entaxy.esb.system.core.events.common.SubscriptionType;
|
||||
import ru.entaxy.esb.system.core.events.handler.util.EventHandlerConstant;
|
||||
import ru.entaxy.esb.system.core.events.handler.util.EventHelper;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SubscriptionRouteGenerator extends RouteBuilder {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SubscriptionRouteGenerator.class);
|
||||
|
||||
private static Map<String, RouteDefinition> routeMap = new HashMap<>();
|
||||
|
||||
private List<SystemSubscription> subscriptions;
|
||||
private EventHelper eventHelper;
|
||||
private final PropertiesHelper propertiesHelper;
|
||||
|
||||
public SubscriptionRouteGenerator(List<SystemSubscription> subscriptions, EventHelper eventHelper, PropertiesHelper propertiesHelper) {
|
||||
this.subscriptions = subscriptions;
|
||||
this.eventHelper = eventHelper;
|
||||
this.propertiesHelper = propertiesHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
LOG.debug("SubscriptionRouteGenerator: finded " + (subscriptions != null ? subscriptions.size() : "null") + " subscriptions");
|
||||
|
||||
if (subscriptions != null && !subscriptions.isEmpty()) {
|
||||
for (SystemSubscription subscription : subscriptions) {
|
||||
LOG.debug("Handle subscription topic: " + subscription.getEventTopic().getName() + " system " + subscription.getSystem().getName());
|
||||
generateReceivingRoute(subscription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateReceivingRoute(SystemSubscription subscription) {
|
||||
if (SubscriptionType.PUSH.equals(subscription.getType())) {
|
||||
LOG.trace("Generate routes PUSH");
|
||||
RouteDefinition definition = from("jms:topic:" + subscription.getEventTopic().getName()
|
||||
+ "?subscriptionName=" + getEventHelper().getClientId(subscription) + "&subscriptionDurable=true&subscriptionShared=true")
|
||||
.setProperty("topicName").constant(subscription.getEventTopic().getName())
|
||||
.to("system:" + subscription.getSystem().getName())
|
||||
.errorHandler(
|
||||
defaultErrorHandler()
|
||||
.maximumRedeliveries(
|
||||
propertiesHelper.getInteger(EventHandlerConstant.REDELIVERY_MAXIMUMREDELIVERIES,
|
||||
EventHandlerConstant.REDELIVERY_MAXIMUMREDELIVERIES_DEFAULT))
|
||||
.redeliveryDelay(
|
||||
propertiesHelper.getInteger(EventHandlerConstant.REDELIVERY_REDELIVERYDELAY,
|
||||
EventHandlerConstant.REDELIVERY_REDELIVERYDELAY_DEFAULT))
|
||||
);
|
||||
|
||||
routeMap.put(getEventHelper().getClientId(subscription), definition);
|
||||
|
||||
} else if (SubscriptionType.PULL.equals(subscription.getType())) {
|
||||
//TODO
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteRoutes(CamelContext context) throws Exception {
|
||||
List<String> subsNames = subscriptions.stream()
|
||||
.map(s -> getEventHelper().getClientId(s))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
LOG.debug("Delete " + subsNames.size() + " receving routes " + String.join(", ", subsNames));
|
||||
|
||||
|
||||
LOG.trace("Routes before delete " + routeMap.size());
|
||||
List<RouteDefinition> routeToDelete = routeMap.entrySet().stream()
|
||||
.filter(x -> subsNames.contains(x.getKey()))
|
||||
.map(x -> x.getValue())
|
||||
.collect(Collectors.toList());
|
||||
if (routeToDelete != null && routeToDelete.size() > 0) {
|
||||
// context.removeRouteDefinitions(routeToDelete);
|
||||
for (RouteDefinition routeDefinition : routeToDelete) {
|
||||
context.removeRoute(routeDefinition.getRouteId());
|
||||
}
|
||||
|
||||
routeMap = routeMap.entrySet().stream()
|
||||
.filter(x -> !subsNames.contains(x.getKey()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
LOG.trace("Routes after delete " + routeMap.size());
|
||||
}
|
||||
}
|
||||
|
||||
public EventHelper getEventHelper() {
|
||||
if (eventHelper == null) {
|
||||
eventHelper = (EventHelper) OSGIUtils.getServiceReference(
|
||||
FrameworkUtil.getBundle(EventHelper.class).getBundleContext(),
|
||||
EventHelper.class.getName());
|
||||
}
|
||||
return eventHelper;
|
||||
}
|
||||
|
||||
public List<SystemSubscription> getSubscriptions() {
|
||||
return subscriptions;
|
||||
}
|
||||
|
||||
public void setSubscriptions(List<SystemSubscription> subscriptions) {
|
||||
this.subscriptions = subscriptions;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler.util;
|
||||
|
||||
import org.osgi.service.event.Event;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class EventAdminHelper {
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
|
||||
public Event createEvent(String eventTopic) {
|
||||
Event event = new Event(eventTopic, new HashMap<>(properties));
|
||||
properties.clear();
|
||||
return event;
|
||||
}
|
||||
|
||||
public void setProperty(String key, Object value) {
|
||||
properties.put(key, value);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler.util;
|
||||
|
||||
public class EventHandlerConstant {
|
||||
|
||||
public static final String CONFIG_FILE = "ru.entaxy.esb.system.event.handler.cfg";
|
||||
|
||||
public static final String REDELIVERY_MAXIMUMREDELIVERIES = "redelivery.maximumRedeliveries";
|
||||
public static final String REDELIVERY_MAXIMUMREDELIVERIES_DEFAULT = "-1";
|
||||
public static final String REDELIVERY_REDELIVERYDELAY = "redelivery.redeliveryDelay";
|
||||
public static final String REDELIVERY_REDELIVERYDELAY_DEFAULT = "5000";
|
||||
|
||||
private EventHandlerConstant() {
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler.util;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EventHelper {
|
||||
|
||||
public static final String CONSUMER_NAME = "consumer";
|
||||
|
||||
public String getClientId(SystemSubscription subscription) {
|
||||
return subscription.getSystem().getName() + "_" + subscription.getEventTopic().getName();
|
||||
}
|
||||
|
||||
public static java.lang.reflect.Type getType() {
|
||||
return new TypeToken<ArrayList<SystemSubscription>>() {
|
||||
}.getType();
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler.util;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import org.apache.camel.component.gson.GsonDataFormat;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GsonDataFormatInitializer extends GsonDataFormat {
|
||||
|
||||
private Gson gson;
|
||||
|
||||
public GsonDataFormatInitializer() {
|
||||
super();
|
||||
Type type = new TypeToken<ArrayList<SystemSubscription>>() {
|
||||
}.getType();
|
||||
setUnmarshalGenericType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception {
|
||||
if (gson == null) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
if (getExclusionStrategies() != null && !getExclusionStrategies().isEmpty()) {
|
||||
ExclusionStrategy[] strategies = getExclusionStrategies().toArray(new ExclusionStrategy[getExclusionStrategies().size()]);
|
||||
builder.setExclusionStrategies(strategies);
|
||||
}
|
||||
// if (longSerializationPolicy != null) {
|
||||
// builder.setLongSerializationPolicy(longSerializationPolicy);
|
||||
// }
|
||||
if (getFieldNamingPolicy() != null) {
|
||||
builder.setFieldNamingPolicy(getFieldNamingPolicy());
|
||||
}
|
||||
// if (fieldNamingStrategy != null) {
|
||||
// builder.setFieldNamingStrategy(fieldNamingStrategy);
|
||||
// }
|
||||
// if (serializeNulls) {
|
||||
// builder.serializeNulls();
|
||||
// }
|
||||
// if (prettyPrint) {
|
||||
// builder.setPrettyPrinting();
|
||||
// }
|
||||
// if (dateFormatPattern != null) {
|
||||
// builder.setDateFormat(dateFormatPattern);
|
||||
// }
|
||||
|
||||
builder.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY);
|
||||
|
||||
gson = builder.create();
|
||||
|
||||
Field f1 = this.getClass().getSuperclass().getDeclaredField("gson");
|
||||
f1.setAccessible(true);
|
||||
f1.set(this, gson);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-handler
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.handler.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.TypeAdapterFactory;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class HibernateProxyTypeAdapter extends TypeAdapter<HibernateProxy> {
|
||||
|
||||
public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
|
||||
@Override
|
||||
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||
return (HibernateProxy.class.isAssignableFrom(type.getRawType()) ? (TypeAdapter<T>) new HibernateProxyTypeAdapter(gson) : null);
|
||||
}
|
||||
};
|
||||
private final Gson context;
|
||||
|
||||
private HibernateProxyTypeAdapter(Gson context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HibernateProxy read(JsonReader in) throws IOException {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public void write(JsonWriter out, HibernateProxy value) throws IOException {
|
||||
if (value == null) {
|
||||
out.nullValue();
|
||||
return;
|
||||
}
|
||||
// Retrieve the original (not proxy) class
|
||||
Class<?> baseType = Hibernate.getClass(value);
|
||||
// Get the TypeAdapter of the original class, to delegate the serialization
|
||||
TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
|
||||
// Get a filled instance of the original class
|
||||
Object unproxiedValue = value.getHibernateLazyInitializer()
|
||||
.getImplementation();
|
||||
// Serialize the value
|
||||
delegate.write(out, unproxiedValue);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,262 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
events-handler
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
|
||||
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
|
||||
|
||||
<cm:property-placeholder persistent-id="ru.entaxy.esb" update-strategy="reload" placeholder-prefix="$common{">
|
||||
<cm:default-properties>
|
||||
<cm:property name="org.quartz.jobStore.driverDelegateClass"
|
||||
value="org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"/>
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
<cm:property-placeholder
|
||||
persistent-id="ru.entaxy.esb.system.event.handler" update-strategy="reload">
|
||||
<cm:default-properties>
|
||||
<cm:property name="quirtz.job.clean.cron" value="0+0/1+*+*+*+?+*"/><!-- cron - Every minite -->
|
||||
<cm:property name="mode.dev" value="false"/>
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
|
||||
|
||||
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
|
||||
<property name="connectionFactory" ref="pooledConnectionFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="eventHelper" class="ru.entaxy.esb.system.core.events.handler.util.EventHelper"/>
|
||||
|
||||
<bean id="propertiesHelper" class="ru.entaxy.esb.system.common.util.PropertiesHelper">
|
||||
<argument index="0" type="java.lang.String" value="ru.entaxy.esb.system.event.handler.cfg"/>
|
||||
<argument index="1" type="boolean" value="true"/>
|
||||
</bean>
|
||||
|
||||
<bean id="subscriptionProcessingGenerator"
|
||||
class="ru.entaxy.esb.system.core.events.handler.SubscriptionProcessingGenerator">
|
||||
<property name="connectionFactory" ref="pooledConnectionFactory"/>
|
||||
<property name="eventHelper" ref="eventHelper"/>
|
||||
<property name="propertiesHelper" ref="propertiesHelper"/>
|
||||
</bean>
|
||||
|
||||
<bean id="eventAdminHelper" class="ru.entaxy.esb.system.core.events.handler.util.EventAdminHelper"/>
|
||||
|
||||
<reference id="systemSubscriptionService"
|
||||
interface="ru.entaxy.esb.system.core.events.jpa.SystemSubscriptionService"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
|
||||
<reference id="eventTopicService"
|
||||
interface="ru.entaxy.esb.system.core.events.jpa.EventTopicService"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
|
||||
<bean id="gson" class="ru.entaxy.esb.system.core.events.handler.util.GsonDataFormatInitializer">
|
||||
<property name="fieldNamingPolicy" value="LOWER_CASE_WITH_UNDERSCORES"/>
|
||||
</bean>
|
||||
|
||||
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
|
||||
<property name="schedulerFactory" ref="factory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="factory" class="org.quartz.impl.StdSchedulerFactory">
|
||||
<argument>
|
||||
<props>
|
||||
<prop key="org.quartz.scheduler.instanceName">entaxy</prop>
|
||||
<prop key="org.quartz.scheduler.instanceId">AUTO</prop>
|
||||
<prop key="org.quartz.scheduler.skipUpdateCheck">true</prop>
|
||||
|
||||
<prop key="org.quartz.jobStore.driverDelegateClass">$common{org.quartz.jobStore.driverDelegateClass}
|
||||
</prop>
|
||||
<prop key="org.quartz.jobStore.isClustered">true</prop>
|
||||
<prop key="org.quartz.jobStore.clusterCheckinInterval">5000</prop>
|
||||
<prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
|
||||
<prop key="org.quartz.jobStore.dataSource">cache</prop>
|
||||
<prop key="org.quartz.dataSource.cache.jndiURL">osgi:service/entaxy.esb.cache</prop>
|
||||
|
||||
<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
|
||||
<prop key="org.quartz.threadPool.threadCount">1</prop>
|
||||
</props>
|
||||
</argument>
|
||||
</bean>
|
||||
|
||||
|
||||
<camelContext id="handler-context" xmlns="http://camel.apache.org/schema/blueprint">
|
||||
|
||||
<route id="handlerInit" autoStartup="true">
|
||||
<from uri="timer:handlerInit?repeatCount=1"/>
|
||||
<to uri="bean-fix:systemSubscriptionService?method=listByDeleted(false)"/>
|
||||
|
||||
<bean ref="subscriptionProcessingGenerator" method="construct(${exchange})"/>
|
||||
</route>
|
||||
|
||||
<route id="prepareSubscriberConsumer">
|
||||
<from uri="direct-vm:prepareSubscriberConsumer"/>
|
||||
|
||||
<bean beanType="java.util.Collections"
|
||||
method="singletonList(ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription)"/>
|
||||
|
||||
<to uri="direct:subscriptionNotifyCluster"/>
|
||||
</route>
|
||||
|
||||
<route id="prepareSubscriberRoute">
|
||||
<from uri="direct-vm:prepareSubscriberRoute"/>
|
||||
<bean beanType="java.util.Collections"
|
||||
method="singletonList(ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription)"/>
|
||||
<to uri="direct-vm:prepareSubscriberRoutes"/>
|
||||
</route>
|
||||
|
||||
<route id="prepareSubscriberRoutes">
|
||||
<from uri="direct-vm:prepareSubscriberRoutes"/>
|
||||
|
||||
<setProperty name="subscribe">
|
||||
<simple resultType="boolean">true</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:subscriptionNotifyCluster"/>
|
||||
</route>
|
||||
|
||||
<route id="deleteSubscriberConsumer">
|
||||
<from uri="direct-vm:deleteSubscriberConsumer"/>
|
||||
|
||||
<bean beanType="java.util.Collections"
|
||||
method="singletonList(ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription)"/>
|
||||
|
||||
<setProperty name="bodyHolder">
|
||||
<simple>${body}</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:subscriptionNotifyCluster"/>
|
||||
|
||||
<setBody>
|
||||
<simple>${exchangeProperty.bodyHolder}</simple>
|
||||
</setBody>
|
||||
|
||||
<bean ref="subscriptionProcessingGenerator" method="destruct(${exchange})"/>
|
||||
</route>
|
||||
|
||||
<route id="deleteSubscriberConsumers">
|
||||
<from uri="direct-vm:deleteSubscriberConsumers"/>
|
||||
|
||||
<setProperty name="bodyHolder">
|
||||
<simple>${body}</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:subscriptionNotifyCluster"/>
|
||||
|
||||
<setBody>
|
||||
<simple>${exchangeProperty.bodyHolder}</simple>
|
||||
</setBody>
|
||||
|
||||
<bean ref="subscriptionProcessingGenerator" method="destruct(${exchange})"/>
|
||||
</route>
|
||||
|
||||
<route id="deleteSubscriberRoute">
|
||||
<from uri="direct-vm:deleteSubscriberRoute"/>
|
||||
<bean beanType="java.util.Collections"
|
||||
method="singletonList(ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription)"/>
|
||||
<to uri="direct-vm:deleteSubscriberRoutes"/>
|
||||
</route>
|
||||
|
||||
<route id="deleteSubscriberRoutes">
|
||||
<from uri="direct-vm:deleteSubscriberRoutes"/>
|
||||
|
||||
<setProperty name="subscribe">
|
||||
<simple resultType="boolean">false</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:subscriptionNotifyCluster"/>
|
||||
</route>
|
||||
|
||||
<route id="deleteSubscriberQueues">
|
||||
<from uri="direct-vm:deleteSubscriberQueues"/>
|
||||
|
||||
<bean ref="subscriptionProcessingGenerator" method="destruct(${exchange})"/>
|
||||
</route>
|
||||
|
||||
<route id="subscriptionNotifyCluster">
|
||||
<from uri="direct:subscriptionNotifyCluster"/>
|
||||
<log message="SEND subscription event" loggingLevel="TRACE"/>
|
||||
<marshal>
|
||||
<custom ref="gson"/>
|
||||
</marshal>
|
||||
|
||||
<bean ref="eventAdminHelper" method="setProperty('subscribe', ${exchangeProperty.subscribe})"/>
|
||||
<bean ref="eventAdminHelper" method="setProperty('subscriptions', ${body})"/>
|
||||
<bean ref="eventAdminHelper" method="createEvent('subscription')"/>
|
||||
|
||||
<to uri="eventadmin:subscription"/>
|
||||
</route>
|
||||
|
||||
<route id="handleConsumerRoutes">
|
||||
<from uri="eventadmin:subscription"/>
|
||||
|
||||
<log message=">>>RECEIVE subscription event" loggingLevel="TRACE"/>
|
||||
|
||||
<setProperty name="subscribe">
|
||||
<simple resultType="boolean">${body.getProperty('subscribe')}</simple>
|
||||
</setProperty>
|
||||
|
||||
<setBody>
|
||||
<simple resultType="String">${body.getProperty('subscriptions')}</simple>
|
||||
</setBody>
|
||||
|
||||
<log message=">>>RECEIVE subscription ${body}" loggingLevel="TRACE"/>
|
||||
|
||||
<unmarshal>
|
||||
<custom ref="gson"/>
|
||||
</unmarshal>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.subscribe}</simple>
|
||||
<bean ref="subscriptionProcessingGenerator" method="construct(${exchange})"/>
|
||||
</when>
|
||||
<otherwise>
|
||||
<bean ref="subscriptionProcessingGenerator" method="destructRoute(${exchange})"/>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</route>
|
||||
|
||||
<route id="cleanTopicsJob">
|
||||
<from uri="quartz://cleanTopics?cron={{quirtz.job.clean.cron}}"/>
|
||||
<log message="Job: Clean topics and subscriptions" loggingLevel="DEBUG"/>
|
||||
<to uri="direct-vm:cleanProcess"/>
|
||||
</route>
|
||||
|
||||
<route id="cleanProcess">
|
||||
<from uri="direct-vm:cleanProcess"/>
|
||||
|
||||
<to uri="bean-fix:systemSubscriptionService?method=listByDeleted(true)"/>
|
||||
|
||||
<to uri="direct-vm:deleteSubscriberConsumers"/>
|
||||
|
||||
<to uri="bean-fix:eventTopicService?method=clean"/>
|
||||
|
||||
|
||||
<log message="CleanProcess: Deleted ${body} topics" loggingLevel="TRACE"/>
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
||||
</blueprint>
|
Reference in New Issue
Block a user