Hazelcast Blueprint Camel Karaf

时间:2016-01-29 07:10:22

标签: apache-camel osgi hazelcast apache-karaf blueprint

我是hazelcast的新手并尝试使用blueprint和karaf实现hazelcast。 我在创建实例的第一步陷入困境,尽管它仅仅使用spring工作。 当我在karaf上运行捆绑包时,它会超时。 请忽略bean类名中的拼写错误,除了hazelcast之外,因为我为了安全目的更改了名称。

这是我的蓝图

<?xml version="1.0" encoding="UTF-8"?>
<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.0.0"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
    xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:hz="http://www.hazelcast.com/schema/spring"
    xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
           http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
           http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd
           ">

    <bean id="loaderCacheManager" class="com.LoaderCacheManagerImpl">
        <property name="template" ref="producerTemplate" />
    </bean>

    <bean id="mconStatusMessage" class="com.impl.MCONStatusMessageImpl" />

    <bean id="headerLookupResponseAggregator"
        class="com.aggregator.HeaderLookupResponseAggregator" />

    <bean id="headerLookupRequestProcessor" depends-on="producerTemplate"
        class="com.processor.HeaderLookupRequestProcessor">
        <property name="loaderCacheManager" ref="loaderCacheManager" />
        <property name="assetObjidSQL" value="${lookup.asset_objid}" />
        <property name="wlanConfigSQL" value="${lookup.wlan_config}" />
        <property name="tlserrWpaEaptlsCodeSQL" value="${lookup.tlserr_wpa_eaptls_code}" />
        <property name="currentDateSQL" value="${lookup.CurrentDate}" />
        <property name="hdrObjidSQL" value="${lookup.HdrObjid}" />
        <property name="deviceIdSQL" value="${device.lookup}" />
    </bean>

    <bean id="headerLookupResponseProcessor" depends-on="producerTemplate"
        class="com.processor.HeaderLookupResponseProcessor">
        <property name="loaderCacheManager" ref="loaderCacheManager" />
    </bean>

    <bean id="mconReferenceLookupProcessor"
        class="com.processor.MCONReferenceLookupProcessor">
        <property name="mconLookupQuerySQL" value="${MCON_LOOKUP_QUERY}" />
    </bean>
    <bean id="mconInsertDetailParamProcessor"
        class="com.processor.MCONInsertDetailParamProcessor">
        <property name="mconInsertQuery" value="${MCON_INSERT_QUERY}" />
    </bean>
    <bean id="rowCountAggregator"
        class="com.aggregator.RowCountAggregator" />
    <bean id="headerInsertSQLProcessor"
        class="com.eaderInsertSQLProcessor">
        <property name="headerInsertSQL" value="${Loader.InsertHeader}" />
    </bean>
    <bean id="postLoadSQLProcessor"
        class="com.ostLoadSQLProcessor">
        <property name="updateMCSAssetSQL" value="${PostLoader.updateCMUStatus}" />
    </bean>





    <bean id="hazelCacheDao" class="com.cache.ResetVehicleInitial" />
    <hz:hazelcast id="instance">
        <hz:config>
            <hz:network port="5701" port-auto-increment="false">
                <hz:join>
                    <hz:multicast enabled="false" />
                </hz:join>
            </hz:network>
             <hz:map name="rmdMap" read-backup-data="true">
                <hz:map-store enabled="true" write-delay-seconds="3"
                    initial-mode="EAGER" implementation="hazelCacheDao" />
            </hz:map> 
        </hz:config>
    </hz:hazelcast>


</blueprint>

以下是我推荐的maploader类。现在我在所有测试目的的方法中都返回null。

public class ResetVehicleInitial implements MapLoader<String, String>{


    private static final String DIRECT_LOAD_RESET_VEHICLE_INITIAL="direct:loadResetVehicleInitial";

    @EndpointInject(uri=DIRECT_LOAD_RESET_VEHICLE_INITIAL)
    private ProducerTemplate loadResetVehicleInitial;

    @Override
    public String load(String arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, String> loadAll(Collection<String> vehicleintial) {
        // TODO Auto-generated method stub
        System.out.println("hello");
        List loadValues = loadResetVehicleInitial.requestBody(DIRECT_LOAD_RESET_VEHICLE_INITIAL, vehicleintial, List.class);
        System.out.println(loadValues);
        return null;
    }

    @Override
    public Iterable<String> loadAllKeys() {
        // TODO Auto-generated method stub
        return null;
    }

}

根据Jereme的建议,我根据java类修改了我的xml:

<?xml version="1.0" encoding="UTF-8"?>
<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.0.0"
    xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
    xmlns:camel="http://camel.apache.org/schema/blueprint" xmlns:hz="http://www.hazelcast.com/schema/spring"
    xsi:schemaLocation="
           http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
           http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
           http://www.hazelcast.com/schema/spring http://www.hazelcast.com/schema/spring/hazelcast-spring-3.5.xsd
           ">

    <bean id="loaderCacheManager" class="com.LoaderCacheManagerImpl">
        <property name="template" ref="producerTemplate" />
    </bean>

    <bean id="mconStatusMessage" class="com.impl.MCONStatusMessageImpl" />

    <bean id="headerLookupResponseAggregator"
        class="com.aggregator.HeaderLookupResponseAggregator" />

    <bean id="headerLookupRequestProcessor" depends-on="producerTemplate"
        class="com.processor.HeaderLookupRequestProcessor">
        <property name="loaderCacheManager" ref="loaderCacheManager" />
        <property name="assetObjidSQL" value="${lookup.asset_objid}" />
        <property name="wlanConfigSQL" value="${lookup.wlan_config}" />
        <property name="tlserrWpaEaptlsCodeSQL" value="${lookup.tlserr_wpa_eaptls_code}" />
        <property name="currentDateSQL" value="${lookup.CurrentDate}" />
        <property name="hdrObjidSQL" value="${lookup.HdrObjid}" />
        <property name="deviceIdSQL" value="${device.lookup}" />
    </bean>

    <bean id="headerLookupResponseProcessor" depends-on="producerTemplate"
        class="com.processor.HeaderLookupResponseProcessor">
        <property name="loaderCacheManager" ref="loaderCacheManager" />
    </bean>

    <bean id="mconReferenceLookupProcessor"
        class="com.processor.MCONReferenceLookupProcessor">
        <property name="mconLookupQuerySQL" value="${MCON_LOOKUP_QUERY}" />
    </bean>
    <bean id="mconInsertDetailParamProcessor"
        class="com.processor.MCONInsertDetailParamProcessor">
        <property name="mconInsertQuery" value="${MCON_INSERT_QUERY}" />
    </bean>
    <bean id="rowCountAggregator"
        class="com.aggregator.RowCountAggregator" />
    <bean id="headerInsertSQLProcessor"
        class="com.eaderInsertSQLProcessor">
        <property name="headerInsertSQL" value="${Loader.InsertHeader}" />
    </bean>
    <bean id="postLoadSQLProcessor"
        class="com.ostLoadSQLProcessor">
        <property name="updateMCSAssetSQL" value="${PostLoader.updateCMUStatus}" />
    </bean>




    <bean id="hazelCacheDao" class="com.ge.trans.loader.qnx.cache.ResetVehicleInitial"/>
    <bean id="instance" class="com.hazelcast.core.Hazelcast"
        factory-method="newHazelcastInstance">
        <constructor-arg>
            <bean class="com.hazelcast.config.Config">
                <property name="groupConfig">
                    <bean class="com.hazelcast.config.GroupConfig">
                        <property name="name" value="local" />
                        <property name="password" value="local" />
                    </bean>
                </property>
                <property name="networkConfig">
                    <bean class="com.hazelcast.config.NetworkConfig">
                        <property name="port" value="7001" />
                        <property name="portAutoIncrement" value="true" />
                        <property name="join">
                            <bean class="com.hazelcast.config.JoinConfig">
                                <property name="multicastConfig">
                                    <bean class="com.hazelcast.config.MulticastConfig">
                                        <property name="enabled" value="false" />
                                    </bean>
                                </property>
                                <property name="tcpIpConfig">
                                    <bean class="com.hazelcast.config.TcpIpConfig">
                                        <property name="enabled" value="true" />
                                        <property name="members" value="3.192.20.22, 3.192.18.110" />
                                    </bean>
                                </property>
                            </bean>
                        </property>
                    </bean>
                </property>
                <property name="mapConfigs">
                    <map>
                        <entry key="dataSyncDetails">
                            <bean class="com.hazelcast.config.MapConfig">
                                <property name="name" value="rmdMap" />
                                <property name="backupCount" value="2" />
                                <property name="timeToLiveSeconds" value="0" />
                                <property name="evictionPolicy" value="LRU" />
                                <property name="maxIdleSeconds" value="0" />
                                <property name="evictionPercentage" value="25" />
                                <property name="maxSizeConfig">
                                    <bean class="com.hazelcast.config.MaxSizeConfig">
                                        <property name="size" value="10000"></property>
                                        <property name="maxSizePolicy" value="USED_HEAP_PERCENTAGE"></property>
                                    </bean>
                                </property>
                                <property name="mapStoreConfig">
                                    <bean class="com.hazelcast.config.MapStoreConfig">
                                        <property name="enabled" value="true"></property>
                                        <property name="writeDelaySeconds" value="0"></property>
                                        <property name="implementation" ref="hazelCacheDao" />
                                        <property name="initialLoadMode" value="EAGER"></property>
                                    </bean>
                                </property>
                            </bean>
                        </entry>
                    </map>

                </property>
            </bean>
        </constructor-arg>
    </bean>


</blueprint>

但现在收到以下错误:

org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to validate xml
    at org.apache.aries.blueprint.parser.Parser.validate(Parser.java:288)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:317)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:270)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:233)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[11:org.apache.aries.util:1.0.1.redhat-610379]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[11:org.apache.aries.util:1.0.1.redhat-610379]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[11:org.apache.aries.util:1.0.1.redhat-610379]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[11:org.apache.aries.util:1.0.1.redhat-610379]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[11:org.apache.aries.util:1.0.1.redhat-610379]
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1103)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4650)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.Felix$4.run(Felix.java:2123)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.Felix.runInContext(Felix.java:2147)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2121)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)[org.apache.felix.framework-4.0.3.redhat-610379.jar:]
    at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:474)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
    at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:404)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
    at org.apache.karaf.features.internal.FeaturesServiceImpl.installFeature(FeaturesServiceImpl.java:400)[22:org.apache.karaf.features.core:2.3.0.redhat-610379]
    at org.apache.karaf.features.command.InstallFeatureCommand.doExecute(InstallFeatureCommand.java:62)[26:org.apache.karaf.features.command:2.3.0.redhat-610379]
    at org.apache.karaf.features.command.FeaturesCommandSupport.doExecute(FeaturesCommandSupport.java:41)[26:org.apache.karaf.features.command:2.3.0.redhat-610379]
    at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
    at org.apache.felix.gogo.commands.basic.AbstractCommand.execute(AbstractCommand.java:35)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
    at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)[15:org.apache.felix.gogo.runtime:0.11.0.redhat-610379]
    at org.apache.karaf.shell.console.jline.Console.run(Console.java:189)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
    at org.apache.karaf.shell.console.jline.DelayedStarted.run(DelayedStarted.java:61)[17:org.apache.karaf.shell.console:2.3.0.redhat-610379]
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'constructor-arg'. One of '{"http://www.osgi.org/xmlns/blueprint/v1.0.0":description, "http://www.osgi.org/xmlns/blueprint/v1.0.0":argument, "http://www.osgi.org/xmlns/blueprint/v1.0.0":property, WC[##other:"http://www.osgi.org/xmlns/blueprint/v1.0.0"]}' is expected.
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)[:]
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)[:]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)[:]
    at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)[:]
    at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)[:]
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)[:]
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)[:]
    at org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(Unknown Source)[:]
    at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)[:]
    at org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(Unknown Source)[:]
    at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)[:]
    at javax.xml.validation.Validator.validate(Unknown Source)[:2.3.0.redhat-610379]
    at org.apache.aries.blueprint.parser.Parser.validate(Parser.java:285)[9:org.apache.aries.blueprint.core:1.0.1.redhat-610379]
    ... 34 more

1 个答案:

答案 0 :(得分:2)

你无法混合&#34;弹簧命名空间&#34;在蓝图配置中,至少使用当前版本的白羊座(显然,你正在使用)

你应该在java类中创建一个HazelcastInstance,而不需要&#39; hz&#39;命名空间。

此外:

  • 双子座蓝图,另一个实施蓝图,支持 在蓝图文件中使用spring命名空间
  • Spring DM,(现在已经过时,但仍可以使用spring&lt; = 3 ..),可以支持使用spring命名空间,在META-INF / spring的弹簧配置中
  • 我在aries蓝图中看到了spring命名空间的实验性支持,但我从未尝试过人格,它是一个正在进行的工作(我还没有看到任何&#34;官方沟通&# 34;关于此功能)