How to install PostgreSQL and pgAdmin4 on Ubuntu 18.04

1. Install PostgreSQL $ sudo apt update $ sudo apt install postgresql postgresql-contrib 2. Update password for postpres user $ sudo -u postgres psql postgres=# ALTER USER user_name WITH PASSWORD 'new_password'; postgres=# \q 3. Install Python PIP for Ubuntu $ sudo apt update $ sudo apt install python3-pip 4. Get the PgAdmin 4 Python Installer at https://www.pgadmin.org/download/pgadmin-4-python-wheel 5. Install pgAdmin4 $ pip install ~/Downloads/pgadmin4*.whl Or for a System wide installation: $ sudo pip install ~/Downloads/pgadmin4*.whl 6. Locate PgAdmin 4 Script $ sudo updatedb $ locate pgAdmin4.py Copy the path displayed from above command. I call it PATH /pgAdmin4.py from now 7. Create config_local.py file for pgAdmin4 local config, add content and save it $ vim PATH /config_local.py import os SERVER_MODE = False DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) LOG_FILE = os.path.join(DATA_DIR...

Phoenix Channels


Channels 

  • Channels add Soft-Real time feature to our application.
  • Channels - Sending and Receiving messages.
  • Senders broadcast messages about Topics.Receivers subscribe to topics so that they can get those messages.

Main Parts in Real Time Communication

1.Socket Handlers

Socket handlers, such as lib/hello_web/channels/user_socket.ex, are modules that authenticate and identify a socket connection and allow you to set default socket assigns for use in all channels.

2.Channel Routes

These are defined in Socket handlers, such as lib/hello_web/channels/user_socket.ex, which makes them distinct from other routes.
They match on the topic string and dispatch matching requests to the given Channel module.


channel "sample_topic:*", HelloWeb.SampleTopicChannel

  • They match on the topic string and dispatch matching requests to the given Channel module.
  • The star character * acts as a wildcard matcher, so in the above example route, requests for sample_topic:pizza and sample_topic:oranges would both be dispatched to the SampleTopicChannel.

3.Channels

Channels are similar to Controllers, they handle events from clients.

Two difference between Channels and Controllers
  1. Channel events can go both directions - incoming and outgoing.
  2. Channel connections also persist beyond a single request/response cycle. 
Each Channel will implement one or more clauses of each of these four callback functions
  • join/3
  • terminate/2
  • handle_in/3
  • handle_out/3

4.PubSub

  • The Phoenix PubSub layer consists of the Phoenix.PubSub module and a variety of modules for different adapters and their GenServers.
  • These modules contain functions which are the nuts and bolts of organizing Channel communication - subscribing to topics, unsubscribing from topics, and broadcasting messages on a topic
  • It is worth noting that these modules are intended for Phoenix’s internal use. Channels use them under the hood to do much of their work. As end users, we shouldn’t have any need to use them directly in our applications.


5.Messages

The Phoenix.Socket.Message module defines a struct with the following keys which denotes a valid message.

  • topic - The string topic or topic:subtopic pair namespace, for example “messages”, “messages:123”
  • event - The string event name, for example “phx_join”
  • payload - The message payload
  • ref - The unique string ref


6.Topics

Topics are string identifiers - names that the various layers use in order to make sure messages end up in the right place. As we saw above, topics can use wildcards. This allows for a useful “topic:subtopic” convention. Often, you’ll compose topics using record IDs from your application layer, such as "users:123".

7.Transports

  • The transport layer is where the rubber meets the road. 
  • The Phoenix.Channel.Transport module handles all the message dispatching into and out of a Channel.





Comments

Popular posts from this blog

Elixir Ecto - My Notes