Coder Social home page Coder Social logo

Comments (4)

anidotnet avatar anidotnet commented on May 23, 2024

I strongly suggest you consider the reference documentation first - http://www.dizitart.org/nitrite-database/doc/2.0.0/index.html#replication

You don't need to manually create the collections in mongo. It will be created by this line from client

DataGateSyncTemplate syncTemplate
        = new DataGateSyncTemplate(dataGateClient, "remote-collection@userId");

Here "remote-collection@userId" is the collection name that will be created in mongo by datagate.

from nitrite-java.

shadialian avatar shadialian commented on May 23, 2024

I've been throw the documentation many times but nothing.

this is my client code.

DataGateClient dataGateClient = new DataGateClient("http://localhost:9090")
        .withAuth("shadi", "123456")
        .withUserAgent(userAgent);
DataGateSyncTemplate syncTemplate
        = new DataGateSyncTemplate(dataGateClient, "test-collection@shadi");
NitriteCollection collection = DB.getCollection("test");      
SyncHandle syncHandle = Replicator.of(DB)
        .forLocal(collection)
        // a DataGate sync template implementation
        .withSyncTemplate(syncTemplate)
        // replication attempt delay of 1 sec
        .delay(timeSpan(1, TimeUnit.SECONDS))
        // both-way replication
        .ofType(ReplicationType.BOTH_WAY)
        // sync event listener
        .withListener(new SyncEventListener() {
            @Override
            public void onSyncEvent(SyncEventData eventInfo) {
              System.out.println("data is synced" + eventInfo.getError());
            }
        })
        .configure();
syncHandle.startSync();
Document doc = createDocument("firstName", "John")
     .put("lastName", "Doe")
     .put("birthDay", new Date())
     //.put("data", new byte[] {1, 2, 3})
     //.put("fruits", new ArrayList<String>() {{ add("apple"); add("orange"); }})
     .put("note", "a quick brown fox jump over the lazy dog");
collection.insert(doc);
DB.commit();
DB.close();

my client application is throwing this exception

data is syncedorg.dizitart.no2.exceptions.SyncException: NO2.11011: error while submitting changes to remote collection
[ScheduledWorker.NO₂] ERROR org.dizitart.no2.sync.DataGateSyncTemplate - Remote error while submitting change feed to remote
org.dizitart.no2.exceptions.SyncException: NO2.11017: HTTP/1.1 400 Bad Request
at org.dizitart.no2.sync.DataGateSyncTemplate.change(DataGateSyncTemplate.java:99)
at org.dizitart.no2.sync.SyncService.mergeChanges(SyncService.java:233)
at org.dizitart.no2.sync.SyncService.mergeChanges(SyncService.java:143)
at org.dizitart.no2.sync.CollectionReplicator.run(CollectionReplicator.java:63)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

the server is throwing this exception

2017-09-06 13:41:35.735 ERROR 5847 --- [qtp914356853-15] o.d.n.d.advices.DataGateApiErrorHandler : DataGate HTTP Error

org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: NO2.3009: document id is an auto generated value and can not be 771985644632835459; nested exception is com.fasterxml.jackson.databind.JsonMappingException: NO2.3009: document id is an auto generated value and can not be 771985644632835459 (through reference chain: org.dizitart.no2.sync.data.ChangeFeed["modifiedDocuments"]->java.util.ArrayList[0]->org.dizitart.no2.Document["_id"])

please if you any idea where would look for a solution

from nitrite-java.

anidotnet avatar anidotnet commented on May 23, 2024

I'll take a look into it tomorrow. Meantime can you also go through one of the datagate junit tests? That might give you an idea if you are doing anything wrong. Now is the night time for me here, so can't be of immediate help. This is the file you need to look at - https://github.com/dizitart/nitrite-database/blob/master/nitrite-datagate/src/test/java/org/dizitart/no2/datagate/DataGateSyncTest.java

from nitrite-java.

anidotnet avatar anidotnet commented on May 23, 2024

Sorry for the late reply, I was so caught up with my work.

Can you please remove the line - DB.close() from your code and test? The close() call will shutdown the sync thread and can cause unexpected result. Meantime, please look into the this test file - SyncIntegrationTest.java for properly initializing your sync code. And let me know if you still see any issue.

from nitrite-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.