Announcement Announcement Module
Collapse
No announcement yet.
client region json serialization not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • client region json serialization not working

    Hi,

    I am trying to get JSON serialization working in a client-server environment.

    The example https://github.com/spring-projects/s...uickstart/json is working fine on my PC. But it's using a local cache/region. Once I replace that with a client-cache and a client region, it stops working.

    My cache server setting:

    Code:
    <gfe:cache-server id="spgCacheServer" port="24165" groups="spgCacheServerGroup"/>
    
        <util:properties id="gemfireProperties">
            <prop key="mcast-port">0</prop>
            <prop key="start-locator">localhost[9999]</prop>
        </util:properties>
    
        <gfe:cache close="true" lazy-init="false" properties-ref="gemfireProperties">  <!-- use default "gemfireCache" as the id -->
            <gfe:dynamic-region-factory/> <!-- dynamically create subregions -->
        </gfe:cache>
    
        <gfe:transaction-manager/>
    
        <gfe:partitioned-region id="tradeRegion" copies="2" total-buckets="4">
            <gfe:cache-listener>
                <bean class="org.mytest.cache.gemfire.test.server.LoggingCacheListener"/>
            </gfe:cache-listener>
        </gfe:partitioned-region>
    
        <context:property-placeholder location="classpath:gemfire.properties"/>
    The file gemfire.properties contains only license.

    My client setting:
    Code:
        <aop:aspectj-autoproxy />
    
        <gfe-data:datasource subscription-enabled="true">
            <gfe-data:locator host="localhost" port="9999"/>
        </gfe-data:datasource>
    
    
    
        <gfe-data:json-region-autoproxy pretty-print="true" convert-returned-collections="false" />
    
    
        <gfe:transaction-manager/> <!-- copy on read is enabled -->
    
        <gfe:client-cache />
    
        <gfe:client-region id="tradeRegion" shortcut="CACHING_PROXY_HEAP_LRU">
            <gfe:cache-listener>
                <bean class="org.mytest.cache.gemfire.test.server.LoggingCacheListener"/>
            </gfe:cache-listener>
    
            <!-- This is to make sure we get updates from the server to keep data consistent -->
            <!-- receive-values=false means we get invalidation events, not changed values. -->
            <!-- true means we want to get values -->
            <gfe:key-interest durable="false" result-policy="NONE" receive-values="true">
                <bean class="java.lang.String">
                    <constructor-arg value="ALL_KEYS" />
                </bean>
            </gfe:key-interest>
    
            <gfe:eviction type="MEMORY_SIZE" threshold="2" action="LOCAL_DESTROY"/> <!-- size in MB -->
        </gfe:client-region>
    
    
    
        <!--<gfe:local-region id="tradeRegion">-->
            <!--<gfe:cache-listener ref="listener"/>-->
        <!--</gfe:local-region>-->
    
        <!--<bean id="listener" class="org.mytest.cache.gemfire.test.server.LoggingCacheListener"/>-->
    
        <bean id="tradeTemplate" class="org.springframework.data.gemfire.GemfireTemplate">
            <property name="region" ref="tradeRegion"/>
        </bean>
    
        <bean id="client" class="org.mytest.cache.gemfire.test1.client.TemplateCacheClient">
            <property name="template" ref="tradeTemplate"/>
        </bean>
    The cache contains only objects, not JSON strings.

    Could you please take a look what I am missing?

    Appreciate it.
    Rick

    P.S., I googled everything related to client-cache, but couldn't find any clue.

  • #2
    Hi Rick,

    Sorry for the late response to your issue storing JSON in Client Cache Regions. I wrote a little example test app to play around with the configuration and found that the SDG JSON support does not work with the SDG datasource bean definition for defining the client-cache/pool. I am not sure why this is yet, but I kept getting a java.io.NotSerializableException on my domain class.

    If you change your datasource bean definition...

    Code:
    <gfe-data:datasource subscription-enabled="true">
        <gfe-data:locator host="localhost" port="9999"/>
    </gfe-data:datasource>
    To...

    Code:
    <gfe:pool id="locatorConnectionPool" subscription-enabled="true">
        <gfe:locator host="localhost" port="9999"/>
    </gfe:pool>
    
    <gfe:client-cache pool-name="locatorConnectionPool"/>
    You should be golden.

    I have attached my example test code for your reference. There are a few differences...

    1. I did not doing anything with subscriptions and interests.
    2. My Client (local) Region is a PROXY, not a CACHING_PROXY (but, should not matter).
    3. I setup my Server to embed a Locator and be Manager so that you can connect with Gfsh.
    4. what else...

    Have a look. Hope this helps.

    Cheers,
    John

    Comment


    • #3
      Hmm, does not like my ZIP file attachment; seems to want to "render" it, argh.

      Comment

      Working...
      X