Exemple #1
0
    private static void getBulkDocs(Couchbase.Core.IBucket bucket, List <string> keys)
    {
        var watch = Stopwatch.StartNew();

        var multiGet = bucket.Get <dynamic>(keys, new ParallelOptions
        {
            MaxDegreeOfParallelism = 4
        }, 4);

        watch.Stop();
        var elapsedMs = watch.ElapsedMilliseconds;

        Console.WriteLine("Bulk Read time: " + elapsedMs + "ms");

        if (OUTPUT_READS)
        {
            foreach (var item in multiGet)
            {
                if (!item.Value.Success)
                {
                    Console.WriteLine("Failed to read key: " + item.Value.Message);
                }
                else
                {
                    Console.WriteLine(item.Key + " has value: \n" + item.Value.Value);
                }
            }
        }
    }
Exemple #2
0
    private static void createDocs(Couchbase.Core.IBucket bucket)
    {
        for (int i = 0; i <= DOC_COUNT; i++)
        {
            var document = new Document <dynamic>
            {
                Id      = i.ToString(),
                Content = new
                {
                    name = "Couchbase test application"
                }
            };

            //Console.WriteLine(document.Id);

            var upsert = bucket.Upsert(document);

            // Console.WriteLine(upsert.Status);

            if (upsert.Success)
            {
                var get = bucket.GetDocument <dynamic>(i.ToString());
                document = get.Document;
                //var msg = string.Format("{0} {1}!", document.Id, document.Content.name);
                //Console.WriteLine(msg);
            }
        }
    }
Exemple #3
0
    private async static void getBulkDocsUsingAsync(Couchbase.Core.IBucket bucket, List <string> keys)
    {
        var watch = Stopwatch.StartNew();

        List <Task <IDocumentResult <dynamic> > > getTasks = new List <Task <IDocumentResult <dynamic> > >();

        foreach (var k in keys)
        {
            Task <IDocumentResult <dynamic> > getTask = bucket.GetDocumentAsync <dynamic>(k);
            getTasks.Add(getTask);
        }

        IDocumentResult <dynamic>[] results = await Task.WhenAll(getTasks);

        watch.Stop();
        var elapsedMs = watch.ElapsedMilliseconds;

        Console.WriteLine("Bulk Read time using Async: " + elapsedMs + "ms");

        if (OUTPUT_READS)
        {
            foreach (var res in results)
            {
                Console.WriteLine(res.Status + " " + res.Content);
            }
        }
    }
Exemple #4
0
        public Database()
        {
            Console.WriteLine("Connecting to database.");
            var cluster = new Cluster(new ClientConfiguration
            {
                Servers = new List <Uri> {
                    new Uri(ServerURI)
                }
            });

            var authenticator = new PasswordAuthenticator("Ecoste", "tidux2284da06");

            cluster.Authenticate(authenticator);
            _bucket = cluster.OpenBucket("FarmWorld");

            var document = new Document <dynamic>
            {
                Id      = "Hello",
                Content = new
                {
                    name = "Couchbase"
                }
            };

            var upsert = _bucket.Upsert(document);
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            Console.WriteLine("\n\nIoT Hub Quickstarts #1 - Simulated device (RB-NEGOTIATOR). Ctrl-C to exit.");

            try
            {
                //Test database connection
                couchbaseCluster = new Cluster(new ClientConfiguration
                {
                    //Servers = new List<Uri> { new Uri("http://127.0.0.1:8091") }
                    Servers = new List <Uri> {
                        new Uri(args[1])
                    }
                });
                couchbaseAuthenticator = new PasswordAuthenticator(args[2], args[3]);
                couchbaseCluster.Authenticate(couchbaseAuthenticator);
                couchbaseBucket = couchbaseCluster.OpenBucket(args[4]);
                couchbaseConnectionInitialised = true;
            }
            catch
            {
                Console.WriteLine("WARNING: Couchbase connection failed to initialise!");
                Console.WriteLine("Press Enter to continue...");
                Console.Read();
                couchbaseConnectionInitialised = false;
            }

            if (args != null && args.Length > 0)
            {
                if (args[0] == "DEVICE")
                {
                    SendDevicesToCloudNonAsync();
                }
                else if (args[0] == "PLACEMENT")
                {
                    SendPlacementsToCloudNonAsync();
                }
                else if (args[0] == "CREATIVE")
                {
                    SendCreativesToCloudNonAsync();
                }
                else
                {
                    Console.WriteLine("Oops, you can only choose from DEVICE, PLACEMENT, CREATIVE...");
                }
            }
            else
            {
                Console.WriteLine("Oops, you need to choose a feed to simulate (DEVICE, PLACEMENT, CREATIVE)...");
            }
        }
 public void Init()
 {
     if (cache == null)
     {
         lock (syncObj)
         {
             var authenticator = new Couchbase.Authentication.PasswordAuthenticator(
                 ConfigurationManager.AppSettings["CouchbaseUsername"],
                 ConfigurationManager.AppSettings["CouchbasePassword"]);
             cluster.Authenticate(authenticator);
             cache = cluster.OpenBucket(ConfigurationManager.AppSettings["CouchbaseBucket"]);
         }
     }
 }
Exemple #7
0
 public CouchBaseDbSnapshotStore()
 {
     _CBBucket = CouchBaseDBPersistence.Instance.Apply(Context.System).SnapShotStoreCBBucket;
 }
 public CouchBaseDbJournal()
 {
     _CBBucket = CouchBaseDBPersistence.Instance.Apply(Context.System).JournalCBBucket;
 }
        public CouchBaseDBExtension(ExtendedActorSystem system)
        {

            if (system == null)
                throw new ArgumentNullException("system");


            // Initialize fallback configuration defaults
            system.Settings.InjectTopLevelFallback(CouchBaseDBPersistence.DefaultConfiguration());

            var HOCON_CB_JournalConfig = system.Settings.Config.GetConfig("akka.persistence.journal.couchbase");

            JournalSettings = new CouchBaseJournalSettings(HOCON_CB_JournalConfig);

            if(JournalSettings.UseClusterHelper)
            {
                JournalCBBucket = ClusterHelper.GetBucket(JournalSettings.BucketName);
                JournalCBCluster = JournalCBBucket.Cluster;
            }
            else
            {
                // Instantiate the connection to the cluster
                JournalCBCluster = new Cluster(JournalSettings.CBClientConfiguration);

                //Open the bucket and make a reference to the CB Client Configuration
                JournalCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(JournalSettings.BucketName);
            }

            // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket
            if (JournalCBCluster == null)
                throw new Exception("CouchBase Journal Cluster could not initialized.");

            // Had to do it this way since by default CB always initializes the default bucket.
            if (JournalCBBucket.Name!=JournalSettings.BucketName)
            {
                throw new Exception("CouchBase Journal bucket could not initialized.");
            }


            // Add Journal Indexes
            // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance
            // First check if the index exists
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId'
            // Create using these:
            // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI

            //string N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'";
            //var result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + JournalCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI";
            //    result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId";
            //result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + JournalCBBucket.Name + "` (PersistenceId,DocumentType) USING GSI";
            //    result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId");
            //}



            var HOCON_CB_SnapshotConfig = system.Settings.Config.GetConfig("akka.persistence.snapshot-store.couchbase");
            SnapShotStoreSettings = new CouchbaseSnapshotSettings(HOCON_CB_SnapshotConfig);

            if(SnapShotStoreSettings.UseClusterHelper)
            {
                SnapShotStoreCBBucket = ClusterHelper.GetBucket(SnapShotStoreSettings.BucketName);
                SnapShotStoreCBCluster = SnapShotStoreCBBucket.Cluster;
            }
            else
            {
                // Are we using the same cluster as the journal?
                if (SnapShotStoreSettings.CBClientConfiguration.Servers.All(JournalSettings.CBClientConfiguration.Servers.Contains))
                {
                    SnapShotStoreCBCluster = JournalCBCluster;

                    // Since we are using the same cluster are we using the same bucket?
                    if (SnapShotStoreSettings.BucketName == JournalSettings.BucketName)
                    {
                        SnapShotStoreCBBucket = JournalCBBucket;
                    }

                }
                else // Instantiate the connection to the new cluster
                {
                    SnapShotStoreCBCluster = new Cluster(SnapShotStoreSettings.CBClientConfiguration);

                    //Open the bucket and make a reference to the CB Client Configuration
                    SnapShotStoreCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(SnapShotStoreSettings.BucketName);
                }
            }

            // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket
            if (SnapShotStoreCBCluster == null)
                throw new Exception("CouchBase Snapshot Store Cluster could not initialized.");

            if (SnapShotStoreCBBucket == null)
            {
                throw new Exception("CouchBase Snapshot Store bucket could not initialized.");
            }

            // Add Snapshot indexes
            // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance
            // First check if the index exists
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId'
            // Create it if it does not
            // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `SSA` (PersistenceId,Timestamp,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI

            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,Timestamp,DocumentType) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_Timestamp");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + SnapShotStoreCBBucket.Name + "` (DocumentType,PersistenceId) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId");
            //}
        }
Exemple #10
0
        public CouchBaseDBExtension(ExtendedActorSystem system)
        {
            if (system == null)
            {
                throw new ArgumentNullException("system");
            }


            // Initialize fallback configuration defaults
            system.Settings.InjectTopLevelFallback(CouchBaseDBPersistence.DefaultConfiguration());

            var HOCON_CB_JournalConfig = system.Settings.Config.GetConfig("akka.persistence.journal.couchbase");

            JournalSettings = new CouchBaseJournalSettings(HOCON_CB_JournalConfig);

            if (JournalSettings.UseClusterHelper)
            {
                JournalCBBucket  = ClusterHelper.GetBucket(JournalSettings.BucketName);
                JournalCBCluster = JournalCBBucket.Cluster;
            }
            else
            {
                // Instantiate the connection to the cluster
                JournalCBCluster = new Cluster(JournalSettings.CBClientConfiguration);

                //Open the bucket and make a reference to the CB Client Configuration
                JournalCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(JournalSettings.BucketName);
            }

            // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket
            if (JournalCBCluster == null)
            {
                throw new Exception("CouchBase Journal Cluster could not initialized.");
            }

            // Had to do it this way since by default CB always initializes the default bucket.
            if (JournalCBBucket.Name != JournalSettings.BucketName)
            {
                throw new Exception("CouchBase Journal bucket could not initialized.");
            }


            // Add Journal Indexes
            // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance
            // First check if the index exists
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId'
            // Create using these:
            // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI

            //string N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'";
            //var result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + JournalCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI";
            //    result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId";
            //result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + JournalCBBucket.Name + "` (PersistenceId,DocumentType) USING GSI";
            //    result = JournalCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId");
            //}



            var HOCON_CB_SnapshotConfig = system.Settings.Config.GetConfig("akka.persistence.snapshot-store.couchbase");

            SnapShotStoreSettings = new CouchbaseSnapshotSettings(HOCON_CB_SnapshotConfig);

            if (SnapShotStoreSettings.UseClusterHelper)
            {
                SnapShotStoreCBBucket  = ClusterHelper.GetBucket(SnapShotStoreSettings.BucketName);
                SnapShotStoreCBCluster = SnapShotStoreCBBucket.Cluster;
            }
            else
            {
                // Are we using the same cluster as the journal?
                if (SnapShotStoreSettings.CBClientConfiguration.Servers.All(JournalSettings.CBClientConfiguration.Servers.Contains))
                {
                    SnapShotStoreCBCluster = JournalCBCluster;

                    // Since we are using the same cluster are we using the same bucket?
                    if (SnapShotStoreSettings.BucketName == JournalSettings.BucketName)
                    {
                        SnapShotStoreCBBucket = JournalCBBucket;
                    }
                }
                else // Instantiate the connection to the new cluster
                {
                    SnapShotStoreCBCluster = new Cluster(SnapShotStoreSettings.CBClientConfiguration);

                    //Open the bucket and make a reference to the CB Client Configuration
                    SnapShotStoreCBBucket = (CouchbaseBucket)JournalCBCluster.OpenBucket(SnapShotStoreSettings.BucketName);
                }
            }

            // Throw an exception if we reach this point without a CB Cluster, CB Config, or Bucket
            if (SnapShotStoreCBCluster == null)
            {
                throw new Exception("CouchBase Snapshot Store Cluster could not initialized.");
            }

            if (SnapShotStoreCBBucket == null)
            {
                throw new Exception("CouchBase Snapshot Store bucket could not initialized.");
            }

            // Add Snapshot indexes
            // Add here to create Global Secondary Indexes that cover (See covering Indexes in Couchbase website) to improve performance
            // First check if the index exists
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp'
            // SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId'
            // Create it if it does not
            // CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `SSA` (PersistenceId,SequenceNr,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `SSA` (PersistenceId,Timestamp,DocumentType) USING GSI
            // CREATE INDEX idxDocumentType_PersistenceId on `SSA` (DocumentType,PersistenceId) USING GSI

            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_SequenceNr'";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_SequenceNr on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,SequenceNr,DocumentType) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_SequenceNr");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId_Timestamp on `" + SnapShotStoreCBBucket.Name + "` (PersistenceId,Timestamp,DocumentType) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId_Timestamp");
            //}
            //N1QLQueryString = "SELECT * FROM system:indexes WHERE name = 'idxDocumentType_PersistenceId_Timestamp";
            //result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //if (result.Rows.Count == 0 && result.Success == true)
            //{
            //    N1QLQueryString = "CREATE INDEX idxDocumentType_PersistenceId on `" + SnapShotStoreCBBucket.Name + "` (DocumentType,PersistenceId) USING GSI";
            //    result = SnapShotStoreCBBucket.Query<dynamic>(N1QLQueryString);
            //    //if (result.Success != true)
            //    //    Debug.Write("Could not create index:idxDocumentType_PersistenceId");
            //}
        }
 public CouchBaseDbJournal()
 {
     _CBBucket = CouchBaseDBPersistence.Instance.Apply(Context.System).JournalCBBucket;
 }
 public CouchBaseDbSnapshotStore()
 {
     _CBBucket = CouchBaseDBPersistence.Instance.Apply(Context.System).SnapShotStoreCBBucket;
 }