<BlockSwitcher>
<Block name="Java">

```java
String tag = "ObserveQuery";
Consumer<DataStoreQuerySnapshot<Post>> onQuerySnapshot = value ->{
        Log.d(tag, "success on snapshot");
        Log.d(tag, "number of records: " + value.getItems().size());
        Log.d(tag, "sync status: " + value.getIsSynced());
};
Consumer<Cancelable> observationStarted = value ->{
        Log.d(tag, "success on cancelable");
};
Consumer<DataStoreException> onObservationError = value ->{
        Log.d(tag, "error on snapshot$value");
};
Action onObservationComplete = () ->{
        Log.d(tag, "complete");
};
QueryPredicate predicate =
        Post.TITLE.beginsWith("post").and(Post.RATING.gt(10));
QuerySortBy querySortBy = new QuerySortBy("post", "rating", QuerySortOrder.ASCENDING);
List<QuerySortBy> sortByList = new ArrayList<QuerySortBy>();
sortByList.add(querySortBy);
ObserveQueryOptions options = new ObserveQueryOptions(predicate, sortByList);
Amplify.DataStore.<Post>observeQuery(
        Post.class,
        options,
        observationStarted,
        onQuerySnapshot,
        onObservationError,
        onObservationComplete
);
```

</Block>
<Block name="Kotlin - Callbacks">

```kotlin
val tag = "ObserveQuery"
val onQuerySnapshot: Consumer<DataStoreQuerySnapshot<Post>> =
    Consumer<DataStoreQuerySnapshot<Post>> { value: DataStoreQuerySnapshot<Post> ->
        Log.d(tag, "success on snapshot")
        Log.d(tag, "number of records: " + value.items.size)
        Log.d(tag, "sync status: " + value.isSynced)
    }

val observationStarted =
    Consumer { _: Cancelable ->
        Log.d(tag, "success on cancelable")
    }
val onObservationError =
    Consumer { value: DataStoreException ->
        Log.d(tag, "error on snapshot $value")
    }
val onObservationComplete = Action {
    Log.d(tag, "complete")
}
val predicate: QueryPredicate =
    Post.TITLE.beginsWith("post").and(Post.RATING.gt(10))
val querySortBy = QuerySortBy("post", "rating", QuerySortOrder.ASCENDING)

val options = ObserveQueryOptions(predicate, listOf(querySortBy))
Amplify.DataStore.observeQuery(
    Post::class.java,
    options,
    observationStarted,
    onQuerySnapshot,
    onObservationError,
    onObservationComplete
)
```

</Block>
<Block name="Kotlin - Coroutines">

```kotlin
val querySortBy = QuerySortBy("post", "rating", QuerySortOrder.ASCENDING)
Amplify.DataStore.observeQuery(
    Post::class,
    ObserveQueryOptions(Post.TITLE.beginsWith("post").and(Post.RATING.gt(10)),
        listOf(querySortBy))
    ).onStart { Log.i("MyAmplifyApp", "Observation began") }
        .catch { Log.e("MyAmplifyApp", "Observation failed", it) }
        .onCompletion { Log.i("MyAmplifyApp", "Observation complete") }
        .collect { value -> Log.i("MyAmplifyApp", "Blog: ${value.items.size}") }
```

</Block>
<Block name="RxJava">

```java
QueryPredicate predicate =
    Post.TITLE.beginsWith("post")
        .and(Post.RATING.gt(10));
QuerySortBy querySortBy = new QuerySortBy("post", "rating", QuerySortOrder.ASCENDING);
List<QuerySortBy> sortByList = new ArrayList<QuerySortBy>();
sortByList.add(querySortBy);
ObserveQueryOptions options = new ObserveQueryOptions(predicate, sortByList);
rxDataStore.observeQuery(Model.class, options).subscribe(
    modelDataStoreQuerySnapshot -> {
        Log.d("mySampleApp", "success on snapshot");
        Log.d("mySampleApp", "number of records: " + modelDataStoreQuerySnapshot.getItems().size());
        Log.d("mySampleApp", "sync status: " + modelDataStoreQuerySnapshot.getIsSynced());
    });
```

</Block>
</BlockSwitcher>
