1.0.4 • Published 15 days ago

@teamteanpm2024/soluta-autem-perspiciatis v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

@teamteanpm2024/soluta-autem-perspiciatis

Apollo graphql subscriptions over Kafka, using kafkajs. Inspired on graphql-kafka-subscriptions.

Communication is done through 1 kafka topic specified in the KafkaPubSub create function. Then channels are used to identify the right subscription.

Installation

  npm install @teamteanpm2024/soluta-autem-perspiciatis
  yarn add @teamteanpm2024/soluta-autem-perspiciatis

Usage

Kafka Pub Sub

import { Kafka } from 'kafkajs';
import { KafkaPubSub } from '@teamteanpm2024/soluta-autem-perspiciatis'

export const pubsub = KafkaPubSub.create({
  topic: 'my-topic',
  kafka: new Kafka({/* ... */})
  groupIdPrefix: "my-group-id-prefix", // used for kafka pub/sub,
  producerConfig: {}, // optional kafkajs producer configuration
  consumerConfig: {} // optional kafkajs consumer configuration
})

Subscription Resolver

{
    collaboration: {
      resolve: (payload: KafkaMessage) => {
        // payload.value will be whatever you sent
        return payload.value;
      },
      subscribe: (_, args) => {
        return pubsub.asyncIterator<YourType>("my channel");
      }
    }
  };

You can also use the subscription payload for the channel.

{
    collaboration: {
      resolve: (payload: KafkaMessage) => {
        // what you publish will end up passing through here and to the client
        return payload.value;
      },
      subscribe: (_, args) => {
        // this is called from the client
        return pubsub.asyncIterator<YourType>(`channel-${args.myId}`);
      }
    }
  };

Publication

Somewhere in your code, you call this:

pubsub.publish("my channel", {
  /* your event data */
});

Use the rest of the kafkajs options:

const event = {/* ... */};
const headers = {
  header1: "value"
};
const producerOptions = { /* options from kafka.js.org/docs/producing: acks, timeout, etc */ };

pubsub.publish("my channel", event, headers, producerOptions);

This ends up publishing the event to kafka (to the topic you used to create the kafkaPubSub) and received by all consumers. The consumer which is listening to my channel will send it to the client.

descriptorsdayjstoolstyped arrayUint8ClampedArraypnpm9equalwatchingtypesvaluesTypeBoxRegExp.prototype.flagsslottasklimitedRFC-6455postcssjssliceemitWeakMapRegExp#flagsstringtc39TypedArrayentriesescapeaccessibilitydeterministicpicomatchBigUint64Arrayvariables in cssharmonyES2021signalsFunction.prototype.namepropertiesttyconsolesameValueZeroasciipackagessuperagentcharacterfunctiondatafsfastcopytslibregular expressionprivatehttpsutilitiesbusyes2015structuredClonees-abstractclassesmakeqstypesafepluginiterationfast-deep-cloneviewdebugclassnamesyamltostringtageslintconfigcssstatelessbyteOffsetUint8Arraynegative zeroarraysymbolsoptiondescriptionrgbvalidationreact poseflattenprocessaccessorregexpinstallerextendexpressioncomputed-typestddcircularwindowsimmerexpressargsremovesigintcryptoECMAScript 2021symbolArrayBufferArray.prototype.findLastlookwalkingdircolorstexttelephonefast-clonedatepromiselinewrapruntimereact animationwordwrapfilteravainferencepipedependenciesfigletIteratorcoreString.prototype.matchAlleventEmitterargvtypedarrayYAMLvalueponyfilltrimStartInt8ArraywarningStyleSheetless compilercore-jsvalidlesscsskeyspropdiffspinnersObject.issanitizejwtimportmochalogURLSearchParamschanneltapzodstreams2cjkcommand-lineanimationconcurrencyextraramdagesturesbannerWebSocketsprototypepasswordstyleguideprefixassertpackage managermulti-packageiteratewhatwgkarmatesterencryptionrangeerrorregulargroupBycontainsmoveECMAScript 2018fetchcallbacksharedECMAScript 2020schemehelpersflagsguidminimalsymlinktouchtypedtakeargumentworkeruuidvalidatorchildpyyamlgraphqlstreamscompilerless mixinsinternalexitsetterletmatchesxssestypewhichArray.prototype.flatfixed-widthmobileRxJSredux-toolkitjavascripthigher-orderPromisedragenvironmentformsprotocol-buffersjQueryerror-handlingduplexcodessetImmediateschemamrunested csscoercibleindicatorstylingbrowserlistHyBibddprogresscheckjson-schemaES2018mkdirssomemacosMicrosofttoStringTagbytearktypeweakmapframeworkappflatwritablefullformattingintrinsicextensionreact-hook-formdeepcopysyntaxerroreventDispatcherreact-testing-libraryidlePushsearchclientemojiInt32Arraykeyshimclassnamefastcomparegradients cssinternal sloteveryES6concatMapeslintpluginstatusstreamless.jses5webnamesfastclonezerowordbreakdirectoryjsonschemaawesomesaucecompile lessspecworkspace:*globinspectmodulesspeedObject.entriesSetreduceexit-codequerystringtraverseconnectArraybindeslint-pluginmake dirutilschromeratelimitgetoptconfigurableobjlinkirqjsonpathxdg-openlast@@toStringTagjsxES2019columnassigncopyexeshebangpoint-freedebuggerpostcss-plugincall-bindbluebirdcommandercss variabledotenvspringES2023rfc4122loadingtoolkitimmutableformatECMAScript 6sortedmkdirpchromiumcryptspinnerfile systemutilitypropertyoutputgenericsecmascriptshammergeio-tsmimechineseArray.prototype.containscall-boundES7i18nreadablelrurobustCSSStyleDeclarationnodejsES3startdefineES2015polyfillStreambounduninstalltoSortedbabel-coreiteratorredactfpcolumnsfindLastdatastructurecorslistenersfileinvariantECMAScript 5unicodetoArrayjson-schema-validatorECMAScript 2023eslintreadUnderscorewatchFiledescriptorlengthomitoperating-systemcss nestingstableautoprefixerflagObject.keyshandlersprettygdprjson-schema-validationObjectlanguagebootstrap cssInt16ArraynpmvariablesmimetypesutilObject.valuespush[[Prototype]]fast-copypreprocessorreactes2016defaultrecursivenegativeflatMapenvtacitsideSymbolcachepurestylesheet.envlibphonenumberbuffersarraybuffermoduleES2022quotermdependency managerFloat32ArrayinstalldefinePropertydeep-copystyled-componentsvalidateformes2017saferequestpopmotionexectrimEndwatchserializerisConcatSpreadablereact-hooksbuffershellcollection.es6artmetadatathroatES2020Array.prototype.filteropenses6middlewareAsyncIteratorECMAScript 2015package.jsonpromisesstyledataViewdroponceenumerablees2018jsonreducerBigInt64Arraycode pointswalkbcryptapierrorReflect.getPrototypeOfcharactersreadablestreamprotoconcatcoloursigtermsetPrototypeOfframerArray.prototype.flatMapES5waitstringifierkoreanconfigajaxObject.definePropertyreuserandomArray.prototype.includessetutil.inspectopenerfindsymlinkspreserve-symlinksposecss lesscreateopenECMAScript 2022groupansilockfilebreakxtermmixinsinterruptsmatchAlleditorwaapifseventsfunctionalthrottleperformantbatchcommandlesscensorwebsite256tapebootstrap lessconsumeURLcurllaunchisupcallbindendercss-in-jsregexfullwidthincludessequencesettingswatcherUint32ArrayargumentsthreebabelObservablesuperstructgetchaiawaitrmdirclass-validatorfunctionsdeletestylesless csstoobjectbyteLengthObservablessanitizationES2017writeES2016requireshrinkwrapobjectwrapinputcurriedserializepackageJSON$.extendcalloptimizerRxsyntaxgetPrototypeOfhashequalityStreamspersistentloggingdeepclonehardlinksESnextarraysgetintrinsictranspilerratefromfindLastIndexrm -rfArray.prototype.findLastIndexweaksetspawnbrowserslisthasOwnexecutableargparseESUint16ArraytypeofbundlersignalstringifySymbol.toStringTagstarterObject.fromEntriesefficientvestes-shimsWebSockettypedarraysqueuecollectionieyuphookformfindupeast-asian-widthajvlimitjesthaselectron-0dom-testing-libraryECMAScript 7assertsparentfantasy-landjsdomgetterpositivehttpoffsettranspileECMAScript 3es7lintfind-upnodeECMAScript 2017typanioncallboundprunenamequeryTypeScriptform-validationregular expressionsurlcmdl10njoiperformanceprivate datatrimRighttimenopeECMAScript 2016matchclimime-dbdomredux3dtestECMAScript 2019airbnbcolorauthtestingpatchES8CSSArrayBuffer.prototype.slicesharedarraybufferxhrasyncastnativea11yfastifyclonees8hooksmomenturlsparserfoldermkdirresolveapollotypescriptbrowser0varMapparentsnumberWeakSetmonorepojapaneseFloat64Arrayauthenticationgradients css3idscheme-validationdeep-clonepathuser-streamsdeepwidthparsetermes-shim APIsortrapideventsloggerqueueMicrotaskfast-deep-copyArrayBuffer#sliceoptimistString.prototype.trimfull-widthwgetObject.assigntsxdgdataviewprotobuftrimestreeserializationArray.prototype.flatten
1.0.2

17 days ago

1.0.4

15 days ago

1.0.3

16 days ago

1.0.1

18 days ago

1.0.0

18 days ago