0

我使用以下三个捆绑包制作了一个应用程序

  • myservice-api
    • 包含模型类来传输数据de.myservice.api.model.MyObject
    • de.myservice.api.services.MyService包含具有功能的服务接口void save(MyObject o)
  • myservice-impl
    • 包含实现MyService并通过 DOSGi 提供
  • frontend只是一些MyService通过蓝图引用实现并调用save函数的代码

我使用 Apache Cellar 功能创建了一个集群,其中两个 Karaf 服务器位于不同的机器上。捆绑包像这样部署并显示状态Active

  • machine001.company.int
    • myservice-api
    • frontend
  • machine002.company.int
    • myservice-api
    • myservice-impl

使用cluster:list-nodes的时候显示集群已经搭建好了,使用cluster:service-list我可以看到我的服务是由machine002提供的:

Service Class                       | Provider Node
-----------------------------------------------------------------
de.myservice.api.services.MyService | machine002.company.int:5701

OSGi 链接和东西有效,但是当frontend尝试使用该save功能时,我在服务提供实例上得到以下异常machine002

2017-03-14 12:55:02,250 | WARN  | pool-65-thread-1 | QueueConsumer                    | 328 - org.apache.karaf.cellar.hazelcast - 4.0.3 |
CELLAR HAZELCAST: consumer task failed to poll the queue com.hazelcast.nio.serialization.HazelcastSerializationException: java.lang.ClassNotFoundException: de.myservice.api.model.MyObject
        at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:224)[322:com.hazelcast:3.7.2]
        at com.hazelcast.internal.serialization.impl.StreamSerializerAdapter.read(StreamSerializerAdapter.java:46)[322:com.hazelcast:3.7.2]
        at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:172)[322:com.hazelcast:3.7.2]
        at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:103)[322:com.hazelcast:3.7.2]
        at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrow(InvocationFuture.java:74)[322:com.hazelcast:3.7.2]
        at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:158)[322:com.hazelcast:3.7.2]
        at com.hazelcast.collection.impl.queue.QueueProxySupport.invokeAndGet(QueueProxySupport.java:177)[322:com.hazelcast:3.7.2]
        at com.hazelcast.collection.impl.queue.QueueProxySupport.pollInternal(QueueProxySupport.java:124)[322:com.hazelcast:3.7.2]
        at com.hazelcast.collection.impl.queue.QueueProxyImpl.poll(QueueProxyImpl.java:88)[322:com.hazelcast:3.7.2]
        at org.apache.karaf.cellar.hazelcast.QueueConsumer.run(QueueConsumer.java:93)[328:org.apache.karaf.cellar.hazelcast:4.0.3]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[:1.8.0_45]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)[:1.8.0_45]
        at java.lang.Thread.run(Thread.java:745)[:1.8.0_45]
Caused by: java.lang.ClassNotFoundException: de.myservice.api.model.MyObject
        at org.apache.karaf.cellar.core.utils.CombinedClassLoader.findClass(CombinedClassLoader.java:79)[326:org.apache.karaf.cellar.core:4.0.3]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)[:1.8.0_45]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_45]
        at com.hazelcast.nio.ClassLoaderUtil.tryLoadClass(ClassLoaderUtil.java:151)
        at com.hazelcast.nio.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:120)
        at com.hazelcast.nio.IOUtil$ClassLoaderAwareObjectInputStream.resolveClass(IOUtil.java:358)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1613)[:1.8.0_45]
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1518)[:1.8.0_45]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1774)[:1.8.0_45]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)[:1.8.0_45]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)[:1.8.0_45]
        at java.util.LinkedList.readObject(LinkedList.java:1149)[:1.8.0_45]
        at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_45]
        at java.lang.reflect.Method.invoke(Method.java:497)[:1.8.0_45]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1017)[:1.8.0_45]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1896)[:1.8.0_45]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)[:1.8.0_45]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)[:1.8.0_45]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1993)[:1.8.0_45]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1918)[:1.8.0_45]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1801)[:1.8.0_45]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)[:1.8.0_45]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:371)[:1.8.0_45]
        at com.hazelcast.internal.serialization.impl.JavaDefaultSerializers$JavaSerializer.read(JavaDefaultSerializers.java:219)[322:com.hazelcast:3.7.2]
        ... 12 more

myservice-api捆绑包部署在两台机器上,因此该类应该可用 - 我还必须配置其他东西,以便 hazelcast 知道从哪里获取类以进行反序列化吗?

4

1 回答 1

0

看起来您的 api 包实际上并没有导出所需的包。因此,请确保它确实如此。而且由于它在“服务器”端工作,我确信您的实现包可能包含这些 API 包。因此,请确保您的捆绑包的导出/导入等是正确的。

于 2017-03-15T07:34:09.547 回答