1stSolo

1stSolo

So far I hadn’t been able to figure out how to get or set topic retention values for kafka topics via brod, using versions up to 3.16.3. I can set it when creating a topic by passing name-value pairs when creating topic.

        config = [
          %{name: "retention.ms", value: "-1"},
          %{name: "retention.bytes", value: "-1"}
        ]

Is this even possible via Brod, or one must install Java and kafka client libraries and invoke kafka-configs.sh or kafka_topics.sh to do it? It seems like a huge limitation. For example, I can’t drop and re-create a topic with same retention because I don’t have all of the metadata.

However, I’m looking at https://hexdocs.pm/brod/3.16.3/brod_client.html#get_metadata/2 and it should return

struct()

struct() = #{field_name() => field_value()} | [{field_name(), field_value()}]

but I’m getting a different struct…

I must be missing something.

Showing Posts 1 to 5

lud

lud

What are you receiving as metadata then? Is the field just missing or are you not receiving {ok, kpro:struct()} | {error, any()}?

1stSolo

1stSolo OP

I’m getting

%{
	brokers: [
		%{host: "localhost", node_id: 0, port: 9092, rack: ""}
	],
	cluster_id: "blah", 
	controller_id: 0,
	topics: [
		%{
			error_code: :no_error, 
			is_internal: false, 
			name: "test_topic_creation", 
			partitions: [
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 0, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 5, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 4, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 1, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 6, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 2, replica_nodes: [0]},
				%{error_code: :no_error, isr_nodes: [0], leader_id: 0, partition_index: 3, replica_nodes: [0]}
			]
		}
	]
}
lud

lud

So it does indeed return {ok, #{field_name() => field_value()}} but yeah, sorry, I don’t know another way to get that info. You may look into the kafka_protocol application (kpro modules and friends) but you may have to encode and decode the request yourself.

1stSolo

1stSolo OP

This looks promising, but I need help translating erlang to Elixir.

API spec: kafka_protocol/src/kpro_req_lib.erl at 7147d6e16652b9b1c39758250bdf93ee934ec706 · kafka4beam/kafka_protocol · GitHub

struct():
https://github.com/kafka4beam/kafka_protocol/blob/7147d6e16652b9b1c39758250bdf93ee934ec706/src/kpro.erl#L193

code:

@version 0
@resource_type_topic 2 # I could not find the values in neither code nor documentation (Just INT8 in https://kafka.apache.org/protocol.html#The_Messages_DescribeConfigs), so I got into online Java IDE and did System.out.println(org.apache.kafka.common.resource.ResourceType.TOPIC.ordinal()); "2" came out.

IO.inspect(:kpro_req_lib.describe_configs(@version, [%{resource_type: @resource_type_topic}, %{resource_name: @test_topic}], %{validate_only: true}))

output:

** (ErlangError) Erlang error: {:field_missing, [stack: [{:describe_configs, 0}, :resources, :resource_name], input: %{resource_type: 2}]}
   stacktrace:
    (kafka_protocol 4.0.3) /Users/maximsenin/workspace/cogynt-common/kafka/deps/kafka_protocol/src/kpro_req_lib.erl:459: :kpro_req_lib.enc_struct/3

as the next step, I want to try to use kafka_protocol/src/kpro_req_lib.erl at 7147d6e16652b9b1c39758250bdf93ee934ec706 · kafka4beam/kafka_protocol · GitHub

Also, I don’t understand how to pass in the broker or zk information here - how does it get connected? Can’t find examples anywhere…

1stSolo

1stSolo OP

I solved it using kafka_protocol library, although it was quite a brain tease to figure out how to call Erlang from Elixir, by wrapping :kpro_req_lib.describe_configs, :kpro_brokers.with_connection, :brod_utils.request_sync and :kpro_req_lib.alter_configs APIs. It was very helpful to go through the source code for the unit tests included with kafka_protocol library.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews