initial public commit

This commit is contained in:
2021-09-06 17:46:59 +03:00
commit b744b08829
824 changed files with 91593 additions and 0 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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() {
}
}

View File

@ -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();
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}

View File

@ -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>