How to use @creditkarma/thrift-client - 10 common examples

To help you get started, we’ve selected a few @creditkarma/thrift-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github creditkarma / thrift-server / packages / thrift-server-ecosystem / src / calculator-service.ts View on Github external
async function init(): Promise {
    const SERVER_CONFIG = await config().get('calculator-service')
    const ADD_SERVER_CONFIG = await config().get('add-service')

    // Create thrift client
    const thriftClient: AddService.Client = createHttpClient(
        AddService.Client,
        {
            hostName: ADD_SERVER_CONFIG.host,
            port: ADD_SERVER_CONFIG.port,
            register: [
                ThriftClientZipkinFilter({
                    localServiceName: 'calculator-service',
                    remoteServiceName: 'add-service',
                    tracerConfig: {
                        endpoint: 'http://localhost:9411/api/v1/spans',
                        httpInterval: 1000,
                        httpTimeout: 5000,
                        sampleRate: 1.0,
                    },
                }),
            ],
github creditkarma / thrift-server / packages / thrift-server-ecosystem / src / client.ts View on Github external
const app = express()

    app.use(
        ZipkinTracingExpress({
            localServiceName: 'calculator-client',
            tracerConfig: {
                endpoint: 'http://localhost:9411/api/v1/spans',
                httpInterval: 1000,
                httpTimeout: 5000,
                sampleRate: 1.0,
            },
        }),
    )

    // Create thrift client
    const thriftClient: Calculator.Client = createHttpClient(
        Calculator.Client,
        {
            hostName: SERVER_CONFIG.host,
            port: SERVER_CONFIG.port,
            register: [
                ThriftClientZipkinFilter({
                    localServiceName: 'calculator-client',
                    remoteServiceName: 'calculator-service',
                    tracerConfig: {
                        endpoint: 'http://localhost:9411/api/v1/spans',
                        httpInterval: 1000,
                        httpTimeout: 5000,
                        sampleRate: 1.0,
                    },
                }),
            ],
github creditkarma / thrift-server / packages / thrift-integration / src / express-calculator-service.ts View on Github external
export function createServer(sampleRate: number = 0): express.Application {
    // Create thrift client
    const addServiceClient: AddService.Client = createHttpClient(
        AddService.Client,
        {
            hostName: ADD_SERVER_CONFIG.hostName,
            port: ADD_SERVER_CONFIG.port,
            register:
                sampleRate > 0
                    ? [
                          ThriftClientZipkinFilter({
                              localServiceName: 'calculator-service',
                              remoteServiceName: 'add-service',
                              tracerConfig: {
                                  endpoint: process.env.ZIPKIN_ENDPOINT,
                                  zipkinVersion:
                                      process.env.ZIPKIN_VERSION === 'v2'
                                          ? 'v2'
                                          : 'v1',
github creditkarma / thrift-server / packages / thrift-integration / src / hapi-calculator-service.ts View on Github external
export async function createServer(
    sampleRate: number = 0,
    protocolType: ProtocolType = 'binary',
): Promise {
    // Create thrift client
    const addServiceClient: AddService.Client = createHttpClient(
        AddService.Client,
        {
            hostName: ADD_SERVER_CONFIG.hostName,
            port: ADD_SERVER_CONFIG.port,
            register:
                sampleRate > 0
                    ? [
                          ThriftClientZipkinFilter({
                              localServiceName: 'calculator-service',
                              remoteServiceName: 'add-service',
                              tracerConfig: {
                                  endpoint: process.env.ZIPKIN_ENDPOINT,
                                  zipkinVersion:
                                      process.env.ZIPKIN_VERSION === 'v2'
                                          ? 'v2'
                                          : 'v1',
github creditkarma / thrift-server / packages / thrift-integration / src / client / client.ts View on Github external
app.use([
            ZipkinTracingExpress({
                localServiceName: 'calculator-client',
                tracerConfig: {
                    endpoint: process.env.ZIPKIN_ENDPOINT,
                    zipkinVersion:
                        process.env.ZIPKIN_VERSION === 'v2' ? 'v2' : 'v1',
                    sampleRate,
                    httpInterval: 0,
                },
            }),
        ])
    }

    // Create thrift client
    const thriftClient: Calculator.Client = createHttpClient(
        Calculator.Client,
        {
            hostName: HAPI_CALC_SERVER_CONFIG.hostName,
            port: HAPI_CALC_SERVER_CONFIG.port,
            protocol: protocolType,
            register:
                sampleRate > 0
                    ? [
                          ThriftClientZipkinFilter({
                              localServiceName: 'calculator-client',
                              remoteServiceName: 'calculator-service',
                              tracerConfig: {
                                  endpoint: process.env.ZIPKIN_ENDPOINT,
                                  zipkinVersion:
                                      process.env.ZIPKIN_VERSION === 'v2'
                                          ? 'v2'
github creditkarma / thrift-server / packages / thrift-integration / src / client / connections / index.spec.ts View on Github external
it('should reject for a request to a missing service', async () => {
            const badClient: Calculator.Client = createTcpClient<
                Calculator.Client
            >(Calculator.Client, {
                hostName: 'fakehost',
                port: 8888,
            })

            return badClient.add(5, 7).then(
                (response: number) => {
                    console.log('res: ', response)
                    throw new Error('Should reject with host not found')
                },
                (err: any) => {
                    console.log('err: ', err)
                    expect(err).to.exist()
                },
            )
github creditkarma / thrift-server / packages / thrift-integration / src / client / connections / index.spec.ts View on Github external
it('should reject when middleware rejects', async () => {
            const client = createHttpClient(Calculator.Client, {
                hostName: HAPI_CALC_SERVER_CONFIG.hostName,
                port: HAPI_CALC_SERVER_CONFIG.port,
                register: [
                    {
                        handler(
                            request: IThriftRequest,
                            next: NextFunction,
                        ): Promise {
                            return next().then((res: IRequestResponse) => {
                                if (readThriftMethod(res.body) === 'nope') {
                                    return Promise.resolve(res)
                                } else {
                                    return Promise.reject(
                                        new Error(
                                            `Unrecognized method name: ${readThriftMethod(
                                                res.body,
github creditkarma / thrift-server / packages / thrift-integration / src / hapi / index.spec.ts View on Github external
before(async () => {
        calcServer = await createCalcServer()
        addServer = await createAddServer()
        client = createHttpClient(Calculator.Client, HAPI_CALC_SERVER_CONFIG)

        return Promise.all([calcServer.start(), addServer.start()]).then(() => {
            console.log('Thrift server started')
        })
    })
github creditkarma / thrift-server / packages / thrift-integration / src / express / index.spec.ts View on Github external
return new Promise((resolve, reject) => {
            const app: express.Application = createCalcServer()
            client = createHttpClient(
                Calculator.Client,
                EXPRESS_CALC_SERVER_CONFIG,
            )

            calcServer = app.listen(EXPRESS_CALC_SERVER_CONFIG.port, () => {
                console.log(
                    `Express server listening on port: ${EXPRESS_CALC_SERVER_CONFIG.port}`,
                )
                addServer.start().then(() => resolve())
            })
        })
    })
github creditkarma / thrift-server / packages / thrift-integration / src / client / connections / HttpConnection.spec.ts View on Github external
it('should reject when middleware does not add auth token', async () => {
            const connection: HttpConnection = new HttpConnection({
                serviceName: 'Calculator',
                hostName: HAPI_CALC_SERVER_CONFIG.hostName,
                port: HAPI_CALC_SERVER_CONFIG.port,
                path: HAPI_CALC_SERVER_CONFIG.path,
            })
            const client = new Calculator.Client(connection)

            return client.addWithContext(5, 7).then(
                (response: number) => {
                    throw new Error(
                        `Mehtods should fail when middleware rejects`,
                    )
                },
                (err: any) => {
                    expect(err.message).to.equal('Unauthorized')
                },