Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for streamed remote service invocation responses #3

Open
eliaslindholm opened this issue Jun 15, 2015 · 0 comments
Open

Support for streamed remote service invocation responses #3

eliaslindholm opened this issue Jun 15, 2015 · 0 comments

Comments

@eliaslindholm
Copy link
Contributor

Add support to stream response from server to client:

interface WizerImportService {
    @AstrixStreamed
    Observable<TransactionRecord> getTransactions();
}

// Service implementation
class WizerServer implements WizerImportService {
    @Override
    public Observable<TransactionRecord> getTransactions() {
        return Observable.create(new OnSubscribe<TransactionRecord>() {
            @Override
            public void call(Subscriber<? super TransactionRecord> t1) {
                try {
                    for (TransactionRecord record : streamRecordsFromDisk()) {
                        t1.onNext(record);
                    }
                    t1.onCompleted();
                } catch (Exception e) {
                    t1.onError(e);
                }
            }
        });
    }
}

// Example consumption pattern
class WizerClient {
    WizerImportService wizerImport;

    public void runWizerImpor() {
        wizerImport.getTransactions().doOnNext(processTransaction());
    }

    private Action1<? super TransactionRecord> processTransaction() {
        return new Action1<TransactionRecord>() {
            @Override
            public void call(TransactionRecord t1) {
                // process t1
            }
        };
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant