Thursday, February 8, 2024

Python Client to send messages to Azure EventHub with ConnectionString

 Run this python code to send messages both in JSON format and string, both are sent successfully. You can just run this from your end, it will sure work. Note that the messages sent in NON JSON format will not be visible but the count increases and messages sent in JSON format can be viewed from Azure UI.  Consumer can read all formats of message.

import asyncio

from azure.eventhub import EventData

from azure.eventhub.aio import EventHubProducerClient

EVENT_HUB_CONNECTION_STR =

"Endpoint=sb://genericeventhub.servicebus.windows.net/;

SharedAccessKeyName=RootManageSharedAccessKey;

SharedAccessKey=4cI6t0fjJwhf8i0ZKIjJ+uww27yCsBtnf+AEhIiC9xQ="

EVENT_HUB_NAME = "javaappeh"

async def run():   

    # Create a producer client to send messages to the event hub.

    # Specify a connection string to your event hubs namespace and

    # the event hub name.

    producer = EventHubProducerClient.from_connection_string(

        conn_str=EVENT_HUB_CONNECTION_STR, eventhub_name=EVENT_HUB_NAME

    )

    async with producer:

        # Create a batch.

        event_data_batch = await producer.create_batch()

        # Add events to the batch.

        messagebody = '{"KEY20":"VALUE20","KEY21":"VALUE21","timestamp":"2024-05-17T01:17:00Z"}'

        event_data_batch.add(EventData(messagebody))

        #event_data_batch.add(EventData("Second event"))       

        await producer.send_batch(event_data_batch)

asyncio.run(run())



Dockerfile for Java Spring Boot Application in RHEL8

 FROM registry.access.redhat.com/ubi8/ubi:8.1

WORKDIR /app

RUN yum update -y  && yum install -y wget

RUN pwd

RUN cd /opt && wget --no-check-certificate https://downloads.apache.org/maven/maven-3/3.8.8/binaries/apache-maven-3.8.8-bin.tar.gz

RUN cd /opt && tar -xvf apache-maven-3.8.8-bin.tar.gz

RUN cd /opt && ln -s apache-maven-3.8.8 maven

RUN yum -y install java-17-openjdk

COPY pom.xml .

COPY src ./src

ENV M2_HOME /opt/maven

ENV PATH ${M2_HOME}/bin:${PATH}:/usr/bin

RUN echo $PATH

RUN mvn -version

RUN mvn install -DskipTests

RUN ls target

EXPOSE 8080

ENV PORT 8080

CMD  ["java", "-Dserver.port=8080", "-jar", "/app/target/test-service-0.0.1-SNAPSHOT.jar"]

Azure Red Hat OpenShift cluster

 ARO( cluster):

When Ingress visibility is set as Private, routes default to internal load balancer and when set Public, routes the default to public standard load balancer. Here the default Virtual network traffic routing can changed. Refer to this link: https://learn.microsoft.com/en-au/azure/virtual-network/virtual-networks-udr-overview 

Create Private ARO: https://learn.microsoft.com/en-au/azure/openshift/howto-create-private-cluster-4x

Ingress Controllers for ARO reference: https://www.redhat.com/en/blog/a-guide-to-controller-ingress-for-azure-red-hat-openshift

Azure KeyVault Access and how to use it in Azure Kubernetes Service

 KeyVault Access:

With public access disabled for Azure Keyvaults, the private endpoints (privatelink.vaultcore.azure.net) can be created for azure key valts and will be accessible from VMs within the same virtual network and subnet as that of keyvault private link's virtual network and subnet.

Azure KeyVault can be accessed publicly (outside azure) with allow public networks enabled under networking.

Azure keyvault can be accessed only from certain virtual network with allow public networks only from specified different virtual network.

Links: https://learn.microsoft.com/en-gb/azure/key-vault/general/private-link-service?tabs=portal

Kubernetes & KeyVault:

Azure keyvault can be accessed in kubernetes cluster by configuring "Enable secret store CSI driver" present in "Advanced" tab while creating AKS. After enabling this, you can define azure keyvault in the network accessible by the cluster.

https://azure.github.io/secrets-store-csi-driver-provider-azure/docs/demos/standard-walkthrough/


Related Posts Plugin for WordPress, Blogger...