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

Add instructions for Java #1898

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 63 additions & 1 deletion app/components/ClientSampleCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function ClientSampleCode({
clientSecret?: string
listTopics?: boolean
topics?: string[]
language: 'py' | 'mjs' | 'cjs' | 'c' | 'cs'
language: 'py' | 'mjs' | 'cjs' | 'c' | 'cs' | 'java'
}) {
const domain = useDomain()

Expand Down Expand Up @@ -511,5 +511,67 @@ export function ClientSampleCode({
project.
</>
)
case 'java':
return (
<>
<p>
The following instructions are for the official Kafka command line
tools which use Java and come with either{' '}
<a
rel="external"
href="https://kafka.apache.org/documentation/#quickstart"
>
Apache Kafka
</a>{' '}
or{' '}
<a
rel="external"
href="https://docs.confluent.io/kafka/operations-tools/kafka-tools.html"
>
Confluent
</a>
. However, they should work with most Java code that uses the
official Apache Kafka client libraries.
</p>
Save the configuration below to a file called{' '}
<code>example.properties</code>:
<Highlight
language="properties"
filename="example.properties"
code={dedent(String.raw`
security.protocol = SASL_SSL
sasl.mechanism = OAUTHBEARER
sasl.login.callback.handler.class = org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginCallbackHandler
sasl.oauthbearer.token.endpoint.url = https://auth.${
domain ?? 'gcn.nasa.gov'
}/oauth2/token
sasl.jaas.config = org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
clientId="${clientId}" \
clientSecret="${clientSecret}";
# Warning: don't share the client secret with others.
`)}
/>
<p>Next, open a terminal.</p>
{listTopics && (
<>
Run the following command to list available Kafka topics.
<Highlight
language="sh"
code={`kafka-topics.sh --bootstrap-server kafka.${
domain ?? 'gcn.nasa.gov'
}:9092 --command-config example.properties --list`}
/>
</>
)}
Run the following command to consume Kafka records and print them to
the console.
<Highlight
language="sh"
code={`kafka-console-consumer.sh --bootstrap-server kafka.${
domain ?? 'gcn.nasa.gov'
}:9092 --consumer.config example.properties${topics.map((topic) => ` ${topic}`).join('')}`}
/>
</>
)
}
}
3 changes: 3 additions & 0 deletions app/components/Highlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
*/
import { Icon, Tooltip } from '@trussworks/react-uswds'
import hljs from 'highlight.js/lib/common'
import properties from 'highlight.js/lib/languages/properties'
import { useState } from 'react'
import CopyToClipboard from 'react-copy-to-clipboard'

hljs.registerLanguage('properties', properties)

export function Highlight({
code,
language,
Expand Down
4 changes: 4 additions & 0 deletions app/routes/_gcn.docs.client._index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ For C#, use the [Confluent.Kafka](https://www.nuget.org/packages/Confluent.Kafka

<ClientSampleCode language="cs" />

## Java

<ClientSampleCode language="java" />

## Known Issues

### confluent-kafka-python
Expand Down
3 changes: 3 additions & 0 deletions app/routes/_gcn.docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export default function () {
<Link key="c-1" to="client#c-1">
C#
</Link>,
<Link key="java" to="client#java">
Java
</Link>,
<NavLink key="code-samples" to="client/samples">
Sample Code
</NavLink>,
Expand Down
6 changes: 6 additions & 0 deletions app/routes/_gcn.quickstart.code.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ export default function () {
language="cs"
/>
</Tab>
<Tab label="Java">
<ClientSampleCode
{...{ clientName, clientId, clientSecret, topics, listTopics }}
language="java"
/>
</Tab>
</Tabs>
<Form method="GET" action="../alerts">
<input type="hidden" name="clientId" value={clientId} />
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"jest-environment-jsdom": "^29.7.0",
"jest-transform-stub": "^2.0.0",
"lint-staged": "^15.2.2",
"lowlight": "^3.0.0",
"nasawds": "^4.0.2-beta.1",
"npm-run-all": "^4.1.5",
"oidc-provider": "^8.4.3",
Expand Down
4 changes: 3 additions & 1 deletion remix.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import properties from 'highlight.js/lib/languages/properties'
import { common } from 'lowlight'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
import rehypeClassNames from 'rehype-class-names'
import rehypeExternalLinks from 'rehype-external-links'
Expand Down Expand Up @@ -38,7 +40,7 @@ const esmOnlyModules = [
export default {
mdx: {
rehypePlugins: [
rehypeHighlight,
(options) => rehypeHighlight({ ...common, properties }),
rehypeSlug,
(options) =>
rehypeExternalLinks({
Expand Down
Loading