Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Connect local gemfire locator #6

Open
geekyzk opened this issue Jul 2, 2017 · 7 comments
Open

Connect local gemfire locator #6

geekyzk opened this issue Jul 2, 2017 · 7 comments

Comments

@geekyzk
Copy link

geekyzk commented Jul 2, 2017

Hi,I use gfsh create locator,Can you tell me how using spring-data-gemfire connect ?
I found in google search,but most example is using built-in gemfire。

@jxblum
Copy link
Contributor

jxblum commented Jul 2, 2017

You must use GemFire properties to connect your Spring peer cache application to a Locator, like so...

<util:properties id="gemfireProperties">
    <prop key="name">PeerCacheMemberUsingLocator</prop>
    <prop key="log-level">warning</prop>
    <prop key="locators">localhost[10334]</prop>
</util:properties>

<gfe:cache properties-ref="gemfireProperties"/>

Or, using JavaConfig...

@Configuration
class GemFireConfiguration {

    Properties gemfireProperties() {

        Properties gemfireProperties = new Properties();

        gemfireProperties.setProperty("name", "PeerCacheMemberUsingLocator");
        gemfireProperties.setProperty("log-level", "config");
        gemfireProperties.setProperty("locators", "localhost[10334]");

        return gemfireProperties;
    }

    @Bean
    CacheFactoryBean gemfireCache() {
        CacheFactoryBean gemfireCache = new CacheFactoryBean();

        gemfireCache.setClose(false);
        gemfireCache.setProperties(gemfireProperties());

        return gemfireCache;
    }

    ....
}

Hope this helps.

@geekyzk
Copy link
Author

geekyzk commented Jul 2, 2017

Thank you for your answer, I can ask a more question?
I create a poje and implements DataSerializable,but when I use gfsh query, it throw a ClassNotFoundException deserialize cache value
I mvn install my project to a jar, and reboot my local server add --classpath=/myproject.jar.. and then i query, it throw gemfire.xx.DataSerializable ClassNotFound......
I add --classpath=/myproject.jar,/gemfire-8.5.4.jar, excute a query, it throw a ClassNotFoundException deserialize cache value

@geekyzk
Copy link
Author

geekyzk commented Jul 2, 2017

@jxblum This is output:
First not include jar:

gfsh>start locator --name=locator1
Starting a Geode Locator in /root/test/locator1...
...................................
gfsh>start server --name=server1
Starting a Geode Server in /root/test/server1...
gfsh>list regions
List of regions
--------------------
HDVehicleList_Region
test1

gfsh>query --query="select count(*) from /HDVehicleList_Region"

Result     : true
startCount : 0
endCount   : 20
Rows       : 1

Result
------
252

NEXT_STEP_NAME : END

gfsh>query --query="select * from /HDVehicleList_Region"

Result     : false
startCount : 0
endCount   : 20
Message    : A ClassNotFoundException was thrown while trying to deserialize cached value.

NEXT_STEP_NAME : END

Second: include project jar.

gfsh>start locator --name=locator1 --classpath=/usr/local/software/gemfire/lib/test3.jar
Starting a Geode Locator in /root/test/locator1...
gfsh>start server --name=server1 --classpath=/usr/local/software/gemfire/lib/test3.jar
Starting a Geode Server in /root/test/server1...
gfsh>query --query="select * from /HDVehicleList_Region"
Could not process command due to GemFire error. Error while processing command <query --query="select * from /HDVehicleList_Region" --step-name=SELECT_EXEC> Reason : java.lang.NoClassDefFoundError: com/gemstone/gemfire/DataSerializable

When I add gemfire.jar to classpath. it still throw : A ClassNotFoundException was thrown while trying to deserialize cached value.

@geekyzk
Copy link
Author

geekyzk commented Jul 2, 2017

And I using Pdx. i throw Could not create an instance of a class com.ttaocloud.entity.User,i found in pivotal gemfire docs,but not found say this exception

@geekyzk
Copy link
Author

geekyzk commented Jul 2, 2017

I use java config:

@Configuration
@SuppressWarnings("unused")
public class Application implements CommandLineRunner {

    @Bean
    Properties gemfireProperties() {
        Properties gemfireProperties = new Properties();
        gemfireProperties.setProperty("name", "DataGemFireApplication");
        gemfireProperties.setProperty("mcast-port", "0");
        gemfireProperties.setProperty("log-level", "config");
        gemfireProperties.setProperty("locators", "localhost[10334]");
        return gemfireProperties;
    }

    @Bean
    CacheFactoryBean gemfireCache() {
        CacheFactoryBean gemfireCache = new CacheFactoryBean();
        gemfireCache.setClose(true);
        gemfireCache.setProperties(gemfireProperties());
        return gemfireCache;
    }
     @Autowired
    GemFireCache gemFireCache;

    @Override
    public void run(String... strings) throws Exception {
        Person alice = new Person("Alice", 40);
        Person bob = new Person("Baby Bob", 1);
        Person carol = new Person("Teen Carol", 13);

        Region<Object, Person> hello = gemFireCache.getRegion("hello");
        hello.put(1, alice);
    }

    public static void main(String[] args) throws IOException {
        SpringApplication application = new SpringApplication(Application.class);
        application.setWebEnvironment(false);
        application.run(args);
    }

}

but it don't connect .

[info 2017/07/03 06:54:57.225 HKT <main> tid=0x1] GemFire P2P Listener started on  tcp:///192.168.1.109<v0>:27817

[info 2017/07/03 06:54:57.330 HKT <PingSender> tid=0x20] unable to connect to locator  localhost(null)<v0>:10334

Unable to contact a Locator service.  Operation either timed out or Locator does not exist.  Configured list of locators is "[localhost(null)<v0>:10334]".
gfsh>start locator --name=test_789 --bind-address=localhost
Starting a Geode Locator in /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/test_789...
....
Locator in /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/test_789 on localhost[10334] as test_789 is currently online.
Process ID: 1371
Uptime: 12 seconds
GemFire Version: 9.0.4
Java Version: 1.8.0_131
Log File: /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/test_789/test_789.log
JVM Arguments: -Dgemfire.enable-cluster-configuration=true -Dgemfire.load-cluster-configuration-from-dir=false -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/lib/geode-core-9.0.4.jar:/Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/lib/geode-dependencies.jar

Successfully connected to: JMX Manager [host=192.168.1.109, port=1099]

Cluster configuration service is up and running.

gfsh>start server --name=123 --locators=localhost[10334]
Starting a Geode Server in /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/123...
....
Server in /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/123 on 192.168.1.109[40404] as 123 is currently online.
Process ID: 1395
Uptime: 3 seconds
GemFire Version: 9.0.4
Java Version: 1.8.0_131
Log File: /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/bin/123/123.log
JVM Arguments: -Dgemfire.locators=localhost[10334] -Dgemfire.use-cluster-configuration=true -Dgemfire.start-dev-rest-api=false -XX:OnOutOfMemoryError=kill -KILL %p -Dgemfire.launcher.registerSignalHandlers=true -Djava.awt.headless=true -Dsun.rmi.dgc.server.gcInterval=9223372036854775806
Class-Path: /Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/lib/geode-core-9.0.4.jar:/Users/geekyzk/Downloads/pivotal-gemfire-9.0.4/lib/geode-dependencies.jar

@prasadrpm
Copy link

@jxblum i am using annotation for creating locator @EnableLocator(host="localhost",port=10334) and getting connection refused error when try connect locator via terminal.

@jxblum
Copy link
Contributor

jxblum commented Mar 19, 2019

By terminal, I assume you mean GemFire Shell, or Gfsh?

If so, then you should know that Gfsh does not ultimately communicate with a GemFire Locator. Gfsh must communicate with a GemFire Manager. A Locator and Manager is not the same thing.

If you attempt to connect to a Locator form Gfsh (the default), the Locator proceeds by trying to find an existing Manager in the cluster. If a Manager is found, then the coordinates for the Manager are returned. If a Manager could not be found, and if the Locator is configured correctly, it will become a Manager and serve a dual role.

Regardless, and ultimately, Gfsh connects to a Manager to carry out all operations.

To enable a GemFire Manager, you can use the @EnableManager annotation in addition to @EnableLocator...

@PeerCacheApplication
@EnableLocator
@EnableManager(start = true)
class MyPeerCacheApplication { ... }

For a more complete example, see here.

I also have plenty examples you can play with here. The boot-example starts a Locator and Manager; see here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants