0

我正在尝试写入“贸易”区域的 gemfire 服务器。我的课是这样的:

public class TradeDetails{
String exchange;
String Product;
String Account;
String Quantity;
//getter and setter }

我已经在 gfsh 控制台中部署了 jar。我在 gfsh 控制台上运行的查询是

put --key=1 --value=('exchange':'xyz','Product':'abc','Account':'xyz','Quantity':'123L') --region=/trade --value-class=model.TradeDetails

但我收到一个错误

无法将 JSON 转换为类 model.TradeDetails 的对象。

可能是什么原因?

4

1 回答 1

0

好吧,根据GemFire 文档,您的Gfsh put命令似乎是正确的......

put --key=1 --value=('exchange':'xyz','Product':'abc','Account':'xyz','Quantity':'123L') --region=/trade - -value-class=model.TradeDetails

但是,您的key价值1有点可疑。如果您java.lang.Long在“/trade”区域上使用了关键约束,那么您还需要--key-classput.

我能够成功执行以下操作...

$ gfsh
    _________________________     __
   / _____/ ______/ ______/ /____/ /
  / /  __/ /___  /_____  / _____  / 
 / /__/ / ____/  _____/ / /    / /  
/______/_/      /______/_/    /_/    v8.2.0

Monitor and Manage GemFire

gfsh>connect
Connecting to Locator at [host=localhost, port=10334] ..
Connecting to Manager at [host=10.99.199.3, port=1099] ..
Successfully connected to: [host=10.99.199.3, port=1099]


gfsh>list members
Member Count : 1
Coordinator  : SpringGemFireDataServer (10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312)

         Name           | Id
----------------------- | ----------------------------------------------------
SpringGemFireDataServer | 10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312


gfsh>describe member --name=SpringGemFireDataServer
Name        : SpringGemFireDataServer
Id          : 10.99.199.3(SpringGemFireDataServer:77179)<v0>:47312
Host        : 10.99.199.3
Regions     : People
PID         : 77179
Groups      : 
Used Heap   : 229M
Max Heap    : 3641M
Working Dir : /Users/jblum/pivdev/spring-data-gemfire-tests-workspace/spring-data-gemfire-tests/target
Log file    : /Users/jblum/pivdev/spring-data-gemfire-tests-workspace/spring-data-gemfire-tests/target
Locators    : localhost[10334]

Cache Server Information
Server Bind              : localhost
Server Port              : 40404
Running                  : true
Client Connections       : 0


gfsh>list regions
List of regions
---------------
People


gfsh>describe region --name=/People
..........................................................
Name            : People
Data Policy     : partition
Hosting Members : SpringGemFireDataServer

Non-Default Attributes Shared By Hosting Members  

 Type  | Name | Value
------ | ---- | -----
Region | size | 0


gfsh>
gfsh>put --region=/People --key=1 --key-class=java.lang.Long --value=('firstName':'Jon','lastName':'Doe') --value-class=org.spring.data.gemfire.app.beans.Person
Result      : true
Key Class   : java.lang.Long
Key         : 1
Value Class : org.spring.data.gemfire.app.beans.Person

Value
------
<NULL>

gfsh>
gfsh>describe region --name=/People
..........................................................
Name            : People
Data Policy     : partition
Hosting Members : SpringGemFireDataServer

Non-Default Attributes Shared By Hosting Members  

 Type  | Name | Value
------ | ---- | -----
Region | size | 1

请注意,我的“/People”区域的键类型为java.lang.Long,值类型为org.spring.data.gemfire.app.beans.Person

虽然,当我试图读回“Jon Doe”时,Gfsh吐了……

gfsh>get --region=/People --key=1 --key-class=java.lang.Long --value-class=org.spring.data.gemfire.app.beans.Person
Exception occurred. null

但是,我确实创建了一个(基于 Spring Boot 的)GemFire 客户端缓存应用程序(具有 SpringGemFireClient 的基本配置,它成功地将 Person 拉出

Person is [Jon Doe]

您可以尝试model.TradeDetails使用 Jackson 映射注释来注释您的应用程序域类型,尽管我不确定Gfsh 是否真的使用它们来执行映射,因为我认为(当我上次检查时)Gfsh没有使用 Jackson。不过,也不会痛。无论哪种方式。

请注意,我的服务器是使用这个SpringGemFireDataServer启动的,它基于SpringGemFireServer

希望这有所帮助 :-)。

干杯! 约翰

于 2016-03-04T21:53:02.670 回答