Friday 4 November 2022

Kafka avro serilization and deserilazation

public static T Deserialize<T>(byte[] bytes) where T : ISpecificRecord, new()

        {

            using (var ms = new MemoryStream(bytes))

            {

                var dec = new BinaryDecoder(ms);

                var regenObj = new T();

 

                var reader = new SpecificDefaultReader(regenObj.Schema, regenObj.Schema);

                reader.Read(regenObj, dec);

                return regenObj;

            }

        }

        public static byte[] Serialize<T>(T thisObj) where T : ISpecificRecord

        {

            using (var ms = new MemoryStream())

            {

                var enc = new BinaryEncoder(ms);

                var writer = new SpecificDefaultWriter(thisObj.Schema); // Schema comes from pre-compiled, code-gen phase

                writer.Write(thisObj, enc);

                return ms.ToArray();

            }

        }



public class KafkaPublish : IKafkaPublish

    {

        private readonly IProducer<string, byte[]> _producer;

 

        public KafkaPublish(ProducerConfig config)

        {

            _producer = new ProducerBuilder<string, byte[]>(config).Build();

 

        }

        public async Task<bool> PublishToKafka(Message<string, byte[]> message, string topic)

        {

            var deliveryReport = await _producer.ProduceAsync(topic, new Message<string, byte[]> { Key = message.Key, Value = message.Value, Headers = message.Headers });

            return deliveryReport.Status == PersistenceStatus.Persisted;

        }

    } 

Tuesday 28 June 2016

printing up Arrow and down arrow

Printing up  Arrow and down arrow

Pring Up arrow
System.Text.RegularExpressions.Regex.Unescape("\u2191")
Printing Down arrow
System.Text.RegularExpressions.Regex.Unescape("\u2193")

Friday 22 April 2016

Configuring Sql Session State


Open a command prompt and locate the following path: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 based on your OS version and .NET version
Use the following statement:
Using default ASPState database and SQL security

aspnet_regsql -S serverName -U UserName -P Password -ssadd -sstype p

Using default ASPState database and windows security

aspnet_regsql -S serverName -E -ssadd -sstype p

Using custom database and SQL security

aspnet_regsql -d TableName -S serverName -U UserName -P Password 
-ssadd -sstype c

t - Stores session data in the SQL Server tempdb database. This is the default. If you store session data in the tempdb database, the session data is lost if SQL Server is restarted.
p - Stores session data in the ASPState database instead of in the tempdb database.
c - Stores session data in a custom database. If you specify the c option, you must also include the name of the custom database using the -d option.
In your configuration file:

Using default SQL security:

<sessionstate mode="SQLServer" timeout="20" allowcustomsqldatabase="true"sqlconnectionstring="Data Source=Server;User ID=UserID;Password=Password;"       cookieless="false">

Using default windows security:

<sessionstate mode="SQLServer" timeout="20" allowcustomsqldatabase="true"  sqlconnectionstring="Data Source=Server;Integrated-Security=SSPI;" cookieless="false">

Custom database name:

<sessionstate mode="SQLServer" timeout="20" allowcustomsqldatabase="true"sqlconnectionstring="Data Source=Server;Initial Catalog=tablename;User ID=UserID;Password=Password;" cookieless="false">

Wednesday 13 April 2016

Insert Sql Query formula for Excel


Insert Sql Query formula  for Excel

="Insert into ##temp_ITContractsCountry (TaoxnomyId,Location) VALUES ("& A2 & ","& CONCATENATE("'",B2,"'") &");"

Friday 13 November 2015

Learn English From This Links

grammer.ccc.comment.edu
www.ucl.ac.uk/internet-grammar
hypergrammar/arts
pardueowl-
britishcouncilgrammar(learnenglish)
BBcLearningEnglish
StockexchangeEnglish
English-Test.net

Monday 26 October 2015

Server Error in '/' Application.


A storage mechanism has already been configured for this application

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: SharpArch.Core.PreconditionException: A storage mechanism has already been configured for this application




Solution

I got Same Issue   solved by resetting the iis using following command

                                    Try to run iisreset command

in command prompt

Wednesday 21 October 2015

Crud Operations or(Scaffold ) On MVC using Nhibernate

Crud Operations or(Scaffold ) On MVC  using Nhibernate

CREATE TABLE [dbo].[Employee](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](255) NULL,
      [PhoneNumber] [nvarchar](255) NULL,
      [Designation] [nvarchar](255) NULL,
      [Email] [nvarchar](255) NULL,
      [DeptNo] [int] NULL,
PRIMARY KEY CLUSTERED
(
      [Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[Department]    Script Date: 10/21/2015 17:29:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Department](
      [DeptNo] [int] IDENTITY(1,1) NOT NULL,
      [DeptName] [nvarchar](255) NULL,
      [Location] [nvarchar](255) NULL,
PRIMARY KEY CLUSTERED
(
      [DeptNo] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

Search Keyword