This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request | |
from kafka import KafkaProducer | |
from dataclasses import field, dataclass | |
from datetime import datetime | |
import random | |
import string | |
import uuid | |
import json | |
app = Flask(__name__) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section class="row"> | |
<article class="column"> | |
<h2>Todays Feeds</h2> | |
<ul class="collection"> | |
</ul> | |
</article> | |
</section> | |
<script> | |
document.addEventListener("DOMContentLoaded", function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createSocket = () => { | |
let channel = socket.channel("news:latest", {}) | |
channel.join() | |
.receive( "ok", resp => { | |
console.log("News feed channel joined successfully", resp.news); | |
}).receive("error", resp => { console.log("Unable to join", resp) }); | |
channel.on("news:latest:new", renderNews); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Kafka consumer config | |
config :kaffe, | |
consumer: [ | |
endpoints: [localhost: 9092], | |
topics: ["newsfeed"], # the topic(s) that will be consumed | |
consumer_group: "learning-elixir", # the consumer group for tracking offsets in Kafka | |
message_handler: Consumer, # the module that will process messages | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Consumer do | |
def handle_message(%{key: key, value: value} = message) do | |
IO.inspect(message) | |
IO.puts("#{key}: #{value}") | |
:ok | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule NewsfeedWeb.FeedChannel do | |
use NewsfeedWeb, :channel | |
def join("news:" <> id, _params, socket) do | |
IO.puts(id) | |
IO.puts("+++++") | |
{:ok, %{ },socket} | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp deps do | |
[ | |
{:phoenix, "~> 1.5.9"}, | |
{:phoenix_ecto, "~> 4.1"}, | |
{:ecto_sql, "~> 3.4"}, | |
{:postgrex, ">= 0.0.0"}, | |
{:phoenix_html, "~> 2.11"}, | |
{:phoenix_live_reload, "~> 1.2", only: :dev}, | |
{:phoenix_live_dashboard, "~> 0.4"}, | |
{:telemetry_metrics, "~> 0.4"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section class="row"> | |
<article class="column"> | |
<h2>Todays Feeds</h2> | |
<ul class="collection"> | |
</ul> | |
</article> | |
</section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule NewsfeedWeb.FeedView do | |
use NewsfeedWeb, :view | |
end |
NewerOlder