提问者:小点点

本机客户端-执行连续查询时的序列化异常


我想建立一个简单的Java

在处理响应时得到了未处理的消息类型26,可能序列化不匹配

我只在缓存区域中存储简单的字符串,所以我有点惊讶我遇到了序列化问题。我已经尝试在两侧启用PDX序列化(并且在没有它的情况下运行),它似乎没有区别。有什么想法吗?

这是我的两边代码:

Java

启动服务器,放置一些数据,然后不断更新给定的缓存条目。

public class GeodePoc {

    public static void main(String[] args) throws Exception {

        ServerLauncher serverLauncher = new ServerLauncher.Builder().setMemberName("server1")
                .setServerBindAddress("localhost").setServerPort(10334).set("start-locator", "localhost[20341]")
                .set(ConfigurationProperties.LOG_LEVEL, "trace")
                .setPdxReadSerialized(true)
                .set(ConfigurationProperties.CACHE_XML_FILE, "cache.xml").build();

        serverLauncher.start();
        Cache c = CacheFactory.getAnyInstance();
        Region<String, String> r = c.getRegion("example_region");
        r.put("test1", "value1");
        r.put("test2", "value2");

        System.out.println("Cache server successfully started");

        int i = 0;
        while (true) {
            r.put("test1", "value" + i);
            System.out.println(r.get("test1"));
            Thread.sleep(3000);
            i++;
        }

    }

}

服务器缓存. xml

<?xml version="1.0" encoding="UTF-8"?>
<cache xmlns="http://geode.apache.org/schema/cache" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
    version="1.0">

    <cache-server bind-address="localhost" port="40404"
        max-connections="100" />
    <pdx>
        <pdx-serializer>
            <class-name>org.apache.geode.pdx.ReflectionBasedAutoSerializer</class-name>
            <parameter name="classes">
                <string>java.lang.String</string>
            </parameter>
        </pdx-serializer>
    </pdx>

    <region name="example_region">
        <region-attributes refid="REPLICATE"  />
    </region>


</cache>

.NET客户

public static void GeodeTest()
        {
            Properties<string, string> props = Properties<string, string>.Create();
            props.Insert("cache-xml-file", "<path-to-cache.xml>");

            CacheFactory cacheFactory = new CacheFactory(props)
                .SetPdxReadSerialized(true).SetPdxIgnoreUnreadFields(true)
                .Set("log-level", "info");
            Cache cache = cacheFactory.Create();
            cache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer();

            IRegion<string, string> region = cache.GetRegion<string, string>("example_region");

            Console.WriteLine(region.Get("test2", null));
            PoolManager pManager = cache.GetPoolManager();
            Pool pool = pManager.Find("serverPool");

            QueryService qs = pool.GetQueryService();

            // Regular query example (works)
            Query<string> q = qs.NewQuery<string>("select * from /example_region");
            ISelectResults<string> results = q.Execute();
            Console.WriteLine("Finished query");
            foreach (string result in results)
            {
                Console.WriteLine(result);
            }

            // Continuous Query (does not work)
            CqAttributesFactory<string, object> cqAttribsFactory = new CqAttributesFactory<string, object>();
            ICqListener<string, object> listener = new CacheListener<string, object>();
            cqAttribsFactory.InitCqListeners(new ICqListener<string, object>[] { listener });
            cqAttribsFactory.AddCqListener(listener);
            CqAttributes<string, object> cqAttribs = cqAttribsFactory.Create();

            CqQuery<string, object> cquery = qs.NewCq<string, object>("select * from /example_region", cqAttribs, false);
            Console.WriteLine(cquery.GetState());
            Console.WriteLine(cquery.QueryString);

            Console.WriteLine(">>> Cache query example started.");
            cquery.Execute();

            Console.WriteLine();
            Console.WriteLine(">>> Example finished, press any key to exit ...");
            Console.ReadKey();
        }

.NET缓存监听器

public class CacheListener<TKey, TResult> : ICqListener<TKey, TResult>
    {
        public virtual void OnEvent(CqEvent<TKey, TResult> ev)
        {
            object val = ev.getNewValue() as object;
            TKey key = ev.getKey();
            CqOperation opType = ev.getQueryOperation();
            string opStr = "DESTROY";
            if (opType == CqOperation.OP_TYPE_CREATE)
                opStr = "CREATE";
            else if (opType == CqOperation.OP_TYPE_UPDATE)
                opStr = "UPDATE";
            Console.WriteLine("MyCqListener::OnEvent called with key {0}, op {1}.", key, opStr);
        }
        public virtual void OnError(CqEvent<TKey, TResult> ev)
        {
            Console.WriteLine("MyCqListener::OnError called");
        }
        public virtual void Close()
        {
            Console.WriteLine("MyCqListener::close called");
        }
    }

.NET客户端缓存. xml

<client-cache
    xmlns="http://geode.apache.org/schema/cache"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
    version="1.0">

  <pool name="serverPool" subscription-enabled="true">
    <locator host="localhost" port="20341"/>
  </pool>

  <region name="example_region">
    <region-attributes refid="CACHING_PROXY" pool-name="serverPool" />
  </region>
</client-cache>

共1个答案

匿名用户

这最终成为我的一个简单疏忽。为了使连续查询起作用,您必须在Java端包含gede-cq依赖项。我没有这样做,这导致了异常。