public static async Task ClassCleanup()
    {
        await moviesProvider.DropTablesAsync();

        moviesProvider = null;
        tweetsProvider = null;
    }
Beispiel #2
0
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        moviesProvider = new MoviesProvider(RestApiProvider);
        await moviesProvider.CreateTablesAsync();

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);
    }
Beispiel #3
0
        protected static async Task InitializeDatabase()
        {
            RestApiProvider = KSqlDbRestApiProvider.Create();

            MoviesProvider = new MoviesProvider(RestApiProvider);
            await MoviesProvider.CreateTablesAsync();

            await MoviesProvider.InsertMovieAsync(MoviesProvider.Movie1);
        }
Beispiel #4
0
        public static async Task Main(string[] args)
        {
            var ksqlDbUrl = @"http:\\localhost:8088";

            var httpClientFactory = new HttpClientFactory(new Uri(ksqlDbUrl));
            var restApiProvider   = new KSqlDbRestApiProvider(httpClientFactory);
            var moviesProvider    = new MoviesProvider(restApiProvider);

            await moviesProvider.CreateTablesAsync();

            var contextOptions = CreateQueryStreamOptions(ksqlDbUrl);

            var context = new KSqlDBContext(contextOptions);

            var subscription = context.CreateQuery <Movie>()
                               .Where(p => p.Title != "E.T.")
                               .Where(c => K.Functions.Like(c.Title.ToLower(), "%hard%".ToLower()) || c.Id == 1)
                               .Where(p => p.RowTime >= 1510923225000) //AND RowTime >= 1510923225000
                               .Select(l => new { Id2 = l.Id, l.Title, l.Release_Year, l.RowTime })
                               .Take(2)                                // LIMIT 2
                               .ToObservable()                         // client side processing starts here lazily after subscription. Switches to Rx.NET
                               .ObserveOn(TaskPoolScheduler.Default)
                               .Subscribe(onNext: movie =>
            {
                Console.WriteLine($"{nameof(Movie)}: {movie.Id2} - {movie.Title} - {movie.RowTime}");
                Console.WriteLine();
            }, onError: error => { Console.WriteLine($"Exception: {error.Message}"); }, onCompleted: () => Console.WriteLine("Completed"));

            await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);

            await moviesProvider.InsertMovieAsync(MoviesProvider.Movie2);

            await moviesProvider.InsertLeadAsync(MoviesProvider.LeadActor1);

            try
            {
                await new PullQueryExample().ExecuteAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            Console.WriteLine("Press any key to stop the subscription");

            Console.ReadKey();

            await context.DisposeAsync();

            using (subscription)
            {
            }

            Console.WriteLine("Subscription completed");
        }
    public static async Task ClassInitialize(TestContext context)
    {
        RestApiProvider = KSqlDbRestApiProvider.Create();

        moviesProvider = new MoviesProvider(RestApiProvider);

        await moviesProvider.CreateTablesAsync();

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie2);

        tweetsProvider = new TweetsProvider(RestApiProvider);

        await tweetsProvider.CreateTweetsStream(TweetsStreamName, tweetsTopicName);

        await tweetsProvider.InsertTweetAsync(TweetsProvider.Tweet1, TweetsStreamName);

        await tweetsProvider.InsertTweetAsync(TweetsProvider.Tweet2, TweetsStreamName);
    }
Beispiel #6
0
 public new static async Task ClassCleanup()
 {
     await MoviesProvider.DropTablesAsync();
 }
Beispiel #7
0
    public static async Task Main(string[] args)
    {
        var ksqlDbUrl = @"http:\\localhost:8088";

        var loggerFactory = CreateLoggerFactory();

        var httpClientFactory = new HttpClientFactory(new Uri(ksqlDbUrl));
        var restApiProvider   = new KSqlDbRestApiProvider(httpClientFactory, loggerFactory)
        {
            DisposeHttpClient = false
        };

        restApiProvider.SetCredentials(new BasicAuthCredentials("fred", "letmein"));

        var moviesProvider = new MoviesProvider(restApiProvider);

        await moviesProvider.CreateTablesAsync();

        var contextOptions = CreateQueryStreamOptions(ksqlDbUrl);

        await using var context = new KSqlDBContext(contextOptions, loggerFactory);

        var query = context.CreateQueryStream <Movie>() // Http 2.0
                                                        // var query = context.CreateQuery<Movie>() // Http 1.0
                    .Where(p => p.Title != "E.T.")
                    .Where(c => c.Title.ToLower().Contains("hard".ToLower()) || c.Id == 1)
                    .Where(p => p.RowTime >= 1510923225000)
                    .Select(l => new { Id = l.Id, l.Title, l.Release_Year, l.RowTime })
                    .Take(2); // LIMIT 2

        var ksql = query.ToQueryString();

        Console.WriteLine("Generated ksql:");
        Console.WriteLine(ksql);
        Console.WriteLine();

        using var disposable = query
                               .ToObservable() // client side processing starts here lazily after subscription. Switches to Rx.NET
                               .Finally(() => { Console.WriteLine("Finally"); })
                               .Subscribe(onNext: movie =>
        {
            Console.WriteLine($"{nameof(Movie)}: {movie.Id} - {movie.Title} - {movie.RowTime}");
            Console.WriteLine();
        }, onError: error => { Console.WriteLine($"Exception: {error.Message}"); }, onCompleted: () => Console.WriteLine("Completed"));

        await CreateOrReplaceTableStatement(context);

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie1);

        await moviesProvider.InsertMovieAsync(MoviesProvider.Movie2);

        await moviesProvider.InsertLeadAsync(MoviesProvider.LeadActor1);

        try
        {
            await new PullQueryExample().ExecuteAsync();
        }
        catch (Exception e)
        {
            Console.WriteLine();
            Console.WriteLine(e.Message);
        }

        string explain = await query.ExplainAsStringAsync();

        ExplainResponse[] explainResponses = await query.ExplainAsync();

        Console.WriteLine($"{Environment.NewLine} Explain => ExecutionPlan:");
        Console.WriteLine(explainResponses[0].QueryDescription?.ExecutionPlan);

        Console.WriteLine("Press any key to stop the subscription");

        Console.ReadKey();

        await moviesProvider.DropTablesAsync();

        Console.WriteLine("Finished.");
    }